I have various activites in my android application lets say Activity1,Activity2,Activity3 etc
All are started by intent object on button Click or list view selection event.On Some activites like in Activity1 i store a bundle inside an intent object and then start an Activity2, On the Second Activity the startActivity() method doesnot work is it memory related issue like intent too heavy to go to next Activity3.
Following is my code
Class Activity2 extends Activity
{
private Intent i;
private Button btn;
@Override
protected void onCreate(Bundle b)
{
//super...
i=new Intent(Activity2.this,Activity3.class);
//btn=.....
//following is button click event from which i will navigate to Activity3
btn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(i); //here it crashed
}});
}
Is it memory related issue or coding problem? if coding problem then how else Activity can be started other than intent.
Following is Log
02-05 02:55:53.367: E/AndroidRuntime(4500): FATAL EXCEPTION: main
02-05 02:55:53.367: E/AndroidRuntime(4500): java.lang.RuntimeException: Unable to pause activity {com.example.viva_project/com.example.viva_project.MainActivity}: java.lang.NullPointerException
02-05 02:55:53.367: E/AndroidRuntime(4500): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2358)
02-05 02:55:53.367: E/AndroidRuntime(4500): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2315)
02-05 02:55:53.367: E/AndroidRuntime(4500): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2295)
02-05 02:55:53.367: E/AndroidRuntime(4500): at android.app.ActivityThread.access$1700(ActivityThread.java:117)
02-05 02:55:53.367: E/AndroidRuntime(4500): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
02-05 02:55:53.367: E/AndroidRuntime(4500): at android.os.Handler.dispatchMessage(Handler.java:99)
02-05 02:55:53.367: E/AndroidRuntime(4500): at android.os.Looper.loop(Looper.java:130)
02-05 02:55:53.367: E/AndroidRuntime(4500): at android.app.ActivityThread.main(ActivityThread.java:3687)
02-05 02:55:53.367: E/AndroidRuntime(4500): at java.lang.reflect.Method.invokeNative(Native Method)
02-05 02:55:53.367: E/AndroidRuntime(4500): at java.lang.reflect.Method.invoke(Method.java:507)
02-05 02:55:53.367: E/AndroidRuntime(4500): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
02-05 02:55:53.367: E/AndroidRuntime(4500): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
02-05 02:55:53.367: E/AndroidRuntime(4500): at dalvik.system.NativeStart.main(Native Method)
02-05 02:55:53.367: E/AndroidRuntime(4500): Caused by: java.lang.NullPointerException
02-05 02:55:53.367: E/AndroidRuntime(4500): at com.example.viva_project.MainActivity.onPause(MainActivity.java:309)
02-05 02:55:53.367: E/AndroidRuntime(4500): at android.app.Activity.performPause(Activity.java:3851)
02-05 02:55:53.367: E/AndroidRuntime(4500): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1191)
02-05 02:55:53.367: E/AndroidRuntime(4500): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2345)
02-05 02:55:53.367: E/AndroidRuntime(4500): ... 12 more
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
connectThread.killConnectThread();
}
您必须在清单中提及所有3个活动。
Caused by: java.lang.NullPointerException at com.example.viva_project.MainActivity.onPause(MainActivity.java:309)
the problem is here:
connectThread.killConnectThread();
connectThread
is null
and you are tryin to execute the method killConnectThread()
!
Be sure to have Activity1, Activity2, and Activity3 registered into your Manifest.xml
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.