1

我创建了 Android ActionBarSherlock。我有两个按钮,问题是当我按下后退按钮时,应用程序崩溃了。这是代码:

@Override
    public boolean onMenuItemSelected(int featureId,
            com.actionbarsherlock.view.MenuItem item) {
        // TODO Auto-generated method stub
        switch(item.getItemId()) {
        case R.id.accept: 
            saveState(); 
            setResult(RESULT_OK);
            Toast.makeText(ReminderEditActivity.this, getString(R.string.task_saved_message), Toast.LENGTH_SHORT).show();
            finish(); 
            return true; 
        case R.id.back: 
            Intent i = new Intent(this, ReminderListActivity.class);
            startActivity(i); 

        return super.onMenuItemSelected(featureId, item);}
        return true;
    }

我知道 Intent Activity 有问题。这是 LogCat :

08-22 14:09:28.389: E/AndroidRuntime(433): java.lang.RuntimeException: Unable to pause activity {com.example.girtsreminder/com.example.girtsreminder.ReminderEditActivity}: java.lang.NullPointerException
08-22 14:09:28.389: E/AndroidRuntime(433):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3348)
08-22 14:09:28.389: E/AndroidRuntime(433):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3305)
08-22 14:09:28.389: E/AndroidRuntime(433):  at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3288)
08-22 14:09:28.389: E/AndroidRuntime(433):  at android.app.ActivityThread.access$2500(ActivityThread.java:125)
08-22 14:09:28.389: E/AndroidRuntime(433):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040)
08-22 14:09:28.389: E/AndroidRuntime(433):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 14:09:28.389: E/AndroidRuntime(433):  at android.os.Looper.loop(Looper.java:123)
08-22 14:09:28.389: E/AndroidRuntime(433):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-22 14:09:28.389: E/AndroidRuntime(433):  at java.lang.reflect.Method.invokeNative(Native Method)
08-22 14:09:28.389: E/AndroidRuntime(433):  at java.lang.reflect.Method.invoke(Method.java:521)
08-22 14:09:28.389: E/AndroidRuntime(433):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-22 14:09:28.389: E/AndroidRuntime(433):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-22 14:09:28.389: E/AndroidRuntime(433):  at dalvik.system.NativeStart.main(Native Method)
08-22 14:09:28.389: E/AndroidRuntime(433): Caused by: java.lang.NullPointerException
08-22 14:09:28.389: E/AndroidRuntime(433):  at com.example.girtsreminder.ReminderEditActivity.onSaveInstanceState(ReminderEditActivity.java:272)
08-22 14:09:28.389: E/AndroidRuntime(433):  at android.app.Activity.performSaveInstanceState(Activity.java:1036)
08-22 14:09:28.389: E/AndroidRuntime(433):  at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1180)
08-22 14:09:28.389: E/AndroidRuntime(433):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3330)

有人能找到我的错误吗?

4

3 回答 3

0

在 Intent 活动中,我添加了finish();它有帮助。

于 2013-08-22T10:22:51.173 回答
0

这是第 272 行 ReminderEditActivity.java 中的 NullPointerException。检查一下什么是 NullPointerException,我该如何解决?

于 2013-08-22T10:18:30.633 回答
0

消除

return super.onMenuItemSelected(featureId, item);

并检查您是否已申报活动。

于 2013-08-22T10:21:44.920 回答