I have created Android ActionBarSherlock. And I have two buttons in there the problem is that when I press my back button the app crashes. This is the code:
@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;
}
I know that something is wrong with Intent Activity. This is 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)
Can someone find my mistake?