• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps textview save and reuse

Hello

I come to you because I have one problem and all my tentative doesn't solve my problem.

I would like to save the value of one textview inside on variable, and reuse this variable to put inside one other.

For the moment my code look like that :
Code:
public class mainresult extends Activity {

	TextView h2,h1;
	
	
		public void onCreate(Bundle savedInstanceState) {
			
			super.onCreate(savedInstanceState);
			setContentView(R.layout.result);
			
				h1=(TextView)findViewById(R.id.R1);
				h2=(TextView)findViewById(R.id.R2);
			
			String R=h2.getText().toString(); // this is the action with problem
			if (R==null||R=="0"){
			h1.setText("toto");
			}
			else{
				h1.setText(R);
			}
		}
}

And one thing that I would after it's to save this variable (R) into the cache, for reuse after that the program was closed.

Thanks for your help
 
voici le logcat
06-03 17:50:56.522: INFO/ActivityManager(58): Starting activity: Intent { cmp=gv.tester/.mainresult }
06-03 17:50:56.670: DEBUG/AndroidRuntime(759): Shutting down VM
06-03 17:50:56.670: WARN/dalvikvm(759): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
06-03 17:50:56.681: ERROR/AndroidRuntime(759): Uncaught handler: thread main exiting due to uncaught exception
06-03 17:50:56.711: ERROR/AndroidRuntime(759): java.lang.RuntimeException: Unable to start activity ComponentInfo{gv.tester/gv.tester.mainresult}: java.lang.NullPointerException
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at android.os.Handler.dispatchMessage(Handler.java:99)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at android.os.Looper.loop(Looper.java:123)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at java.lang.reflect.Method.invokeNative(Native Method)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at java.lang.reflect.Method.invoke(Method.java:521)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at dalvik.system.NativeStart.main(Native Method)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): Caused by: java.lang.NullPointerException
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at gv.tester.mainresult.onCreate(mainresult.java:22)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
06-03 17:50:56.711: ERROR/AndroidRuntime(759): ... 11 more
06-03 17:50:56.741: INFO/Process(58): Sending signal. PID: 759 SIG: 3
06-03 17:50:56.741: INFO/dalvikvm(759): threadid=7: reacting to signal 3
06-03 17:50:56.811: INFO/dalvikvm(759): Wrote stack trace to '/data/anr/traces.txt'
06-03 17:51:06.653: WARN/ActivityManager(58): Launch timeout has expired, giving up wake lock!
06-03 17:51:06.660: WARN/ActivityManager(58): Activity idle timeout for HistoryRecord{43e88680 gv.tester/.mainresult}
 
Back
Top Bottom