Note that there are some explanatory texts on larger screens.

plurals
  1. POAction bar home button crashes while back button works
    text
    copied!<p>I'm completely stumped on this one. I have an activity C, when I try and press the back button, it works. But when I use the home/up button in the action bar it just crashes with (see the following error). Here are the parts of my code which deal with the back/up buttons.</p> <p>Activity C:</p> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_offline_viewer); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); } @Override public boolean onPrepareOptionsMenu(Menu menu) { if(!isOnline) { menu.removeItem(R.id.saveRoute); } return true; } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.offline_viewer, menu); return true; } @Override public void onBackPressed() { super.onBackPressed(); finish(); } @Override public boolean onOptionsItemSelected(MenuItem item) { //Get names for saving String[] startParts = onlineFrom.split(","); String startName = startParts[0] + "," + startParts[1]; String[] endParts = onlineTo.split(","); String endName = endParts[0] + "," + endParts[1]; System.out.println(item.getItemId()); switch(item.getItemId()){ //Save xml file or route once pressed case R.id.saveRoute: //TODO:Uncomment once server is ready new DownloadFileFromURL(this, startName, endName).execute(urlForDownload); return true; case android.R.id.home: System.out.println(item.getItemId()); onBackPressed(); return true; } return super.onOptionsItemSelected(item); } </code></pre> <p>Error:</p> <pre><code>08-22 16:15:43.629: W/dalvikvm(4908): threadid=1: thread exiting with uncaught exception (group=0x41c7e888) 08-22 16:15:43.634: E/AndroidRuntime(4908): FATAL EXCEPTION: main 08-22 16:15:43.634: E/AndroidRuntime(4908): java.lang.NullPointerException 08-22 16:15:43.634: E/AndroidRuntime(4908): at com.example.otpxmlgetter.OfflineViewer.onOptionsItemSelected(OfflineViewer.java:185) 08-22 16:15:43.634: E/AndroidRuntime(4908): at android.app.Activity.onMenuItemSelected(Activity.java:2590) 08-22 16:15:43.634: E/AndroidRuntime(4908): at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361) 08-22 16:15:43.634: E/AndroidRuntime(4908): at com.android.internal.widget.ActionBarView$3.onClick(ActionBarView.java:167) 08-22 16:15:43.634: E/AndroidRuntime(4908): at android.view.View.performClick(View.java:4204) 08-22 16:15:43.634: E/AndroidRuntime(4908): at android.view.View$PerformClick.run(View.java:17354) 08-22 16:15:43.634: E/AndroidRuntime(4908): at android.os.Handler.handleCallback(Handler.java:725) 08-22 16:15:43.634: E/AndroidRuntime(4908): at android.os.Handler.dispatchMessage(Handler.java:92) 08-22 16:15:43.634: E/AndroidRuntime(4908): at android.os.Looper.loop(Looper.java:137) 08-22 16:15:43.634: E/AndroidRuntime(4908): at android.app.ActivityThread.main(ActivityThread.java:5232) 08-22 16:15:43.634: E/AndroidRuntime(4908): at java.lang.reflect.Method.invokeNative(Native Method) 08-22 16:15:43.634: E/AndroidRuntime(4908): at java.lang.reflect.Method.invoke(Method.java:511) 08-22 16:15:43.634: E/AndroidRuntime(4908): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) 08-22 16:15:43.634: E/AndroidRuntime(4908): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561) 08-22 16:15:43.634: E/AndroidRuntime(4908): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>Does this have something to do with the fact that there are two possible ways to get to Activity C? Either A->B->C or A->D->C? The fact that the back button still works completely confounds me.</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