切换Activity时报错Unable to stop activity

请教一下大家,哪些原因可能导致下面出现的问题!

程序有两个Activity,从MainActivity启动到NoteActivity时报错,主要是说java.lang.RuntimeException: Unable to stop activity {<包名>/<包名>.MainActivity}: java.lang.NullPointerExceptionCaused by: java.lang.NullPointerException,日志里没有说我的代码哪行有问题,都是些系统自己的类和方法。

两个Activity的声明:

<activity
    android:name=".activity.MainActivity"
    android:theme="@style/AppTheme.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name=".activity.NoteActivity"
    android:theme="@style/AppTheme.NoActionBar" />

启动NoteActivity的代码:

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab_new_note);
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent = new Intent(MainActivity.this, NoteActivity.class);
        intent.putExtra("Open_Type", "newNote");
        startActivity(intent);
    }
});

点了fab按钮后直接报错,完整的错误日志如下:

E/AndroidRuntime: FATAL EXCEPTION: main
  Process: zqy.bysj.todo, PID: 2034
  java.lang.RuntimeException: Unable to stop activity {zqy.bysj.todo/zqy.bysj.todo.activity.MainActivity}: java.lang.NullPointerException
      at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3174)
      at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3220)
      at android.app.ActivityThread.access$1100(ActivityThread.java:135)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1223)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:136)
      at android.app.ActivityThread.main(ActivityThread.java:5001)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:515)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
      at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.NullPointerException
      at android.app.Activity.performStop(Activity.java:5388)
      at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3171)
      at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3220) 
      at android.app.ActivityThread.access$1100(ActivityThread.java:135) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1223) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:136) 
      at android.app.ActivityThread.main(ActivityThread.java:5001) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
      at dalvik.system.NativeStart.main(Native Method) 

请教一下大家,哪些原因可能导致这个问题?谢谢!

附图,看的清楚点。
图片说明

3个回答

只知道提示的是空指针错误,将完整代码贴出来看看

你不会是在NoteActivity里面finish MainActivity了?

你的MainActivity可能其他操作影响了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问