Passing values between one activity to another

  • Replies:1
  • OpenNot stickiedUnanswered
  • Forum posts: 8

Feb 5, 2016 9:54:54 AM via Website

I tried to pass data from one activity to another another activity. I am getting error while running this. Please find my code below. Please help me to rectify my error.

First Activity:

Intent i = new Intent(MainActivity.this, Main1Activity.class);
i.putExtra("myclipboard", text1);
startActivity(i);

Second Activity:

edittext = (EditText) findViewById(R.id.editText1);
Bundle bundle = getIntent().getExtras();
event = bundle.getString("myclipboard");
edittext.setText(event);

Log cat:
02-05 14:21:06.529: E/SpeechRecognizer(2287): no selected voice recognition service
02-05 14:21:09.630: D/AndroidRuntime(2287): Shutting down VM
02-05 14:21:09.630: E/AndroidRuntime(2287): FATAL EXCEPTION: main
02-05 14:21:09.630: E/AndroidRuntime(2287): Process: com.example.ram, PID: 2287
02-05 14:21:09.630: E/AndroidRuntime(2287): java.lang.RuntimeException: Unable to pause activity {com.example.ram/com.example.ram.MainActivity}: java.lang.IllegalArgumentException: Service not registered: android.speech.SpeechRecognizer$Connection@26e36ce
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3381)
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3340)
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3315)
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.app.ActivityThread.-wrap13(ActivityThread.java)
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.os.Handler.dispatchMessage(Handler.java:102)
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.os.Looper.loop(Looper.java:148)
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.app.ActivityThread.main(ActivityThread.java:5417)
02-05 14:21:09.630: E/AndroidRuntime(2287): at java.lang.reflect.Method.invoke(Native Method)
02-05 14:21:09.630: E/AndroidRuntime(2287): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
02-05 14:21:09.630: E/AndroidRuntime(2287): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-05 14:21:09.630: E/AndroidRuntime(2287): Caused by: java.lang.IllegalArgumentException: Service not registered: android.speech.SpeechRecognizer$Connection@26e36ce
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1044)
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.app.ContextImpl.unbindService(ContextImpl.java:1337)
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.content.ContextWrapper.unbindService(ContextWrapper.java:616)
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.speech.SpeechRecognizer.destroy(SpeechRecognizer.java:408)
02-05 14:21:09.630: E/AndroidRuntime(2287): at com.example.ram.MainActivity.onPause(MainActivity.java:118)
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.app.Activity.performPause(Activity.java:6348)
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1311)
02-05 14:21:09.630: E/AndroidRuntime(2287): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3367)
02-05 14:21:09.630: E/AndroidRuntime(2287): ... 10 more
02-05 14:21:11.559: W/System(2328): ClassLoader referenced unknown path: /data/app/com.example.ram-2/lib/x86
02-05 14:21:12.260: D/AndroidRuntime(2328): Shutting down VM
02-05 14:21:12.261: E/AndroidRuntime(2328): FATAL EXCEPTION: main
02-05 14:21:12.261: E/AndroidRuntime(2328): Process: com.example.ram, PID: 2328
02-05 14:21:12.261: E/AndroidRuntime(2328): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ram/com.example.ram.Main1Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.EditText.setText(java.lang.CharSequence)' on a null object reference
02-05 14:21:12.261: E/AndroidRuntime(2328): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
02-05 14:21:12.261: E/AndroidRuntime(2328): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
02-05 14:21:12.261: E/AndroidRuntime(2328): at android.app.ActivityThread.-wrap11(ActivityThread.java)
02-05 14:21:12.261: E/AndroidRuntime(2328): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
02-05 14:21:12.261: E/AndroidRuntime(2328): at android.os.Handler.dispatchMessage(Handler.java:102)
02-05 14:21:12.261: E/AndroidRuntime(2328): at android.os.Looper.loop(Looper.java:148)
02-05 14:21:12.261: E/AndroidRuntime(2328): at android.app.ActivityThread.main(ActivityThread.java:5417)
02-05 14:21:12.261: E/AndroidRuntime(2328): at java.lang.reflect.Method.invoke(Native Method)
02-05 14:21:12.261: E/AndroidRuntime(2328): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
02-05 14:21:12.261: E/AndroidRuntime(2328): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-05 14:21:12.261: E/AndroidRuntime(2328): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.EditText.setText(java.lang.CharSequence)' on a null object reference
02-05 14:21:12.261: E/AndroidRuntime(2328): at com.example.ram.Main1Activity.onCreate(Main1Activity.java:27)
02-05 14:21:12.261: E/AndroidRuntime(2328): at android.app.Activity.performCreate(Activity.java:6237)
02-05 14:21:12.261: E/AndroidRuntime(2328): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
02-05 14:21:12.261: E/AndroidRuntime(2328): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
02-05 14:21:12.261: E/AndroidRuntime(2328): ... 9 more
02-05 14:21:15.316: I/Process(2328): Sending signal. PID: 2328 SIG: 9

  • Forum posts: 270

Feb 5, 2016 10:07:41 PM via Website

02-05 14:21:09.630: E/AndroidRuntime(2287): Process: com.example.ram, PID: 2287
02-05 14:21:09.630: E/AndroidRuntime(2287): java.lang.RuntimeException: Unable to pause activity {com.example.ram/com.example.ram.MainActivity}: java.lang.IllegalArgumentException: Service not registered: android.speech.SpeechRecognizer$Connection@26e36ce

02-05 14:21:09.630: E/AndroidRuntime(2287): at com.example.ram.MainActivity.onPause(MainActivity.java:118)

You have error on MainActivity onPause() method on string 118 of MainActivity.java, check that string.