Note that there are some explanatory texts on larger screens.

plurals
  1. POForce-Close when pressing back button
    text
    copied!<p>I get an error if i press the Hardware-Back-Button in one of my Activitys and I cant figure out where the error lies Here is my code:</p> <pre><code>import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageButton; import android.widget.TextView; import android.widget.Toast; public class NoteScreen extends Activity { /** Called when the activity is first created. */ private EditText mTitleText; private EditText mBodyText; private Long mRowId; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.note_screen); setTitle("Edit Note"); mTitleText = (EditText) findViewById(R.id.title); mBodyText = (EditText) findViewById(R.id.note); ImageButton acceptButton = (ImageButton) findViewById(R.id.accept); mRowId = null; Bundle extras = getIntent().getExtras(); if (extras != null) { String title = extras.getString(NotesDbAdapter.KEY_TITLE); String body = extras.getString(NotesDbAdapter.KEY_BODY); mRowId = extras.getLong(NotesDbAdapter.KEY_ROWID); if (title != null) { mTitleText.setText(title); } if (body != null) { mBodyText.setText(body); } } acceptButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Bundle bundle = new Bundle(); bundle.putString(NotesDbAdapter.KEY_TITLE, mTitleText.getText().toString()); bundle.putString(NotesDbAdapter.KEY_BODY, mBodyText.getText().toString()); if (mRowId != null) { bundle.putLong(NotesDbAdapter.KEY_ROWID, mRowId); } Intent mIntent = new Intent(); mIntent.putExtras(bundle); setResult(RESULT_OK, mIntent); finish(); } }); ImageButton cancelButton = (ImageButton) findViewById(R.id.cancel); cancelButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(NoteScreen.this, MainActivity.class); startActivity(i); finish(); } }); // TODO Auto-generated method stub } } </code></pre> <p>Here is my LogCat:</p> <pre><code>11-23 19:59:10.851: E/AndroidRuntime(1009): FATAL EXCEPTION: main 11-23 19:59:10.851: E/AndroidRuntime(1009): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=0, data=null} to activity {com.reekapps.simplenote/com.reekapps.simplenote.MainActivity}: java.lang.NullPointerException 11-23 19:59:10.851: E/AndroidRuntime(1009): at android.app.ActivityThread.deliverResults(ActivityThread.java:3319) 11-23 19:59:10.851: E/AndroidRuntime(1009): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3362) 11-23 19:59:10.851: E/AndroidRuntime(1009): at android.app.ActivityThread.access$1100(ActivityThread.java:141) 11-23 19:59:10.851: E/AndroidRuntime(1009): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282) 11-23 19:59:10.851: E/AndroidRuntime(1009): at android.os.Handler.dispatchMessage(Handler.java:99) 11-23 19:59:10.851: E/AndroidRuntime(1009): at android.os.Looper.loop(Looper.java:137) 11-23 19:59:10.851: E/AndroidRuntime(1009): at android.app.ActivityThread.main(ActivityThread.java:5041) 11-23 19:59:10.851: E/AndroidRuntime(1009): at java.lang.reflect.Method.invokeNative(Native Method) 11-23 19:59:10.851: E/AndroidRuntime(1009): at java.lang.reflect.Method.invoke(Method.java:511) 11-23 19:59:10.851: E/AndroidRuntime(1009): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 11-23 19:59:10.851: E/AndroidRuntime(1009): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 11-23 19:59:10.851: E/AndroidRuntime(1009): at dalvik.system.NativeStart.main(Native Method) 11-23 19:59:10.851: E/AndroidRuntime(1009): Caused by: java.lang.NullPointerException 11-23 19:59:10.851: E/AndroidRuntime(1009): at com.reekapps.simplenote.MainActivity.onActivityResult(MainActivity.java:171) 11-23 19:59:10.851: E/AndroidRuntime(1009): at android.app.Activity.dispatchActivityResult(Activity.java:5293) 11-23 19:59:10.851: E/AndroidRuntime(1009): at android.app.ActivityThread.deliverResults(ActivityThread.java:3315) 11-23 19:59:10.851: E/AndroidRuntime(1009): ... 11 more 11-23 19:59:43.861: E/Trace(1120): error opening trace file: No such file or directory (2) </code></pre> <p>Does anybody see the error? I have no Idea Thanks in advance</p> <p>EDIT:</p> <pre><code> @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); Bundle extras = intent.getExtras(); switch(requestCode) { case ACTIVITY_CREATE: String title = extras.getString(NotesDbAdapter.KEY_TITLE); String body = extras.getString(NotesDbAdapter.KEY_BODY); mDbHelper.createNote(title, body); fillData(); break; case ACTIVITY_EDIT: Long rowId = extras.getLong(NotesDbAdapter.KEY_ROWID); if (rowId != null) { String editTitle = extras.getString(NotesDbAdapter.KEY_TITLE); String editBody = extras.getString(NotesDbAdapter.KEY_BODY); mDbHelper.updateNote(rowId, editTitle, editBody); } fillData(); break; } } </code></pre> <p>I posted my onActivityResult, maybe the error is somewhere in there.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload