Friday, 16 August 2013

activity crashes when going back home

activity crashes when going back home

I have an edit task activity with a single edittext view. When i click the
back button on the action bar, the database is updated and the log even
registers it, but the activity crashes while going back. The main activity
does display the text that was added in the task activity. Here is the
code for the home button:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
EditText t = (EditText) findViewById(R.id.editText1);
String s = t.getText().toString();
if (s.equalsIgnoreCase("")) {
Toast.makeText(this, "enter the task description first!!",
Toast.LENGTH_LONG);
} else {
Task task = new Task(s, 0);
db.addTask(task);
Log.d("tasker", "data added");
adapt.notifyDataSetChanged();
}
setResult(RESULT_OK);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
Whats wrong?
Here is the log:
08-16 17:56:05.117: E/AndroidRuntime(6162): FATAL EXCEPTION: main
08-16 17:56:05.117: E/AndroidRuntime(6162): java.lang.NullPointerException
08-16 17:56:05.117: E/AndroidRuntime(6162): at
com.example.tasker.NewTask.onOptionsItemSelected(NewTask.java:62)
08-16 17:56:05.117: E/AndroidRuntime(6162): at
android.app.Activity.onMenuItemSelected(Activity.java:2552)
08-16 17:56:05.117: E/AndroidRuntime(6162): at
com.android.internal.widget.ActionBarView$3.onClick(ActionBarView.java:167)
08-16 17:56:05.117: E/AndroidRuntime(6162): at
android.view.View.performClick(View.java:4204)
08-16 17:56:05.117: E/AndroidRuntime(6162): at
android.view.View$PerformClick.run(View.java:17355)
08-16 17:56:05.117: E/AndroidRuntime(6162): at
android.os.Handler.handleCallback(Handler.java:725)
08-16 17:56:05.117: E/AndroidRuntime(6162): at
android.os.Handler.dispatchMessage(Handler.java:92)
08-16 17:56:05.117: E/AndroidRuntime(6162): at
android.os.Looper.loop(Looper.java:137)
08-16 17:56:05.117: E/AndroidRuntime(6162): at
android.app.ActivityThread.main(ActivityThread.java:5234)
08-16 17:56:05.117: E/AndroidRuntime(6162): at
java.lang.reflect.Method.invokeNative(Native Method)
08-16 17:56:05.117: E/AndroidRuntime(6162): at
java.lang.reflect.Method.invoke(Method.java:525)
08-16 17:56:05.117: E/AndroidRuntime(6162): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
08-16 17:56:05.117: E/AndroidRuntime(6162): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
08-16 17:56:05.117: E/AndroidRuntime(6162): at
dalvik.system.NativeStart.main(Native Method)

No comments:

Post a Comment