簡體   English   中英

Sherlock中的Android ActionBar Intent

[英]Android ActionBar Intent in Sherlock

我已經創建了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;
    }

我知道意圖活動有問題。 這是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)

有人可以找到我的錯誤嗎?

這是第272行ReminderEditActivity.java中的NullPointerException。 檢查一下什么是NullPointerException,以及如何解決?

去掉

return super.onMenuItemSelected(featureId, item);

並檢查您是否已宣布活動。

在Intent活動中,我添加了finish(); 它有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM