Question

I have an app that has been pretty stable so far, and I decided I wanted to add a MapView to it. The MapView is in a HorizontalScrollView if that makes a difference. I converted my main activity to extend MapActivity and added the isRouteDisplayed() function. I can compile and run it, scrolling over to see my MapView loading correctly.

My issue is when super.onDestroy() gets called. For some reason, the program crashes.

LogCat:

10-17 18:32:17.109: E/AndroidRuntime(5477): Caused by: java.lang.NullPointerException 10-17 18:32:17.109: E/AndroidRuntime(5477): at com.google.android.maps.MapActivity.onDestroy(MapActivity.java:500) 10-17 18:32:17.109: E/AndroidRuntime(5477): at com.appsmith.mapit.MainActivity.onDestroy(MainActivity.java:177) 10-17 18:32:17.109: E/AndroidRuntime(5477): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2663) 10-17 18:32:17.109: E/AndroidRuntime(5477): ... 11 more

 @Override
 public void onDestroy()
 {
        internalSave();
        writeOutLookupTable("Unit");
        gpsManager.removeUpdates(myListener);
        super.onDestroy(); //MainActivity.java Line 177
        finish();
 }

Any advice for troubleshooting this would be greatly appreciated.

EDIT: Got it! I implemented an onPause() that had identical information to my onDestroy() (it was my solution to keep the GPS from being active when the app wasn't in use). Commenting out the onPause() makes everything happy again. Thanks for the help!

Was it helpful?

Solution

You dont need to call finish(); inside onDestroy(), finish() as docs says: "Call this when your activity is done and should be closed.", so if you are in onDestroy() then your activitiy is already being finished

Also super.onDestroy(); is usually being put at the top of onDestroy().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top