1

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!

Dr. Cyanide
  • 520
  • 1
  • 7
  • 21
  • Forget line 177, your null is at line `MapActivity.java:500`. Let's see that part. – Geobits Oct 18 '12 at 00:56
  • @Geobits it says com.google.android.maps.MapActivity.onDestroy(MapActivity.java:500). It is the source code of Android. That's what makes this question so difficult to answer. – MarchingHome Oct 18 '12 at 01:01
  • http://www.androidadb.com/source/android-comapping-read-only/viewer/project/src/com/comapping/android/map/MapActivity.java.html – marcinj Oct 18 '12 at 01:04
  • 1
    Damn, I missed that somehow. thanks. – Geobits Oct 18 '12 at 01:04
  • looks like in line : view.onSearch(searchResult, s);, view is null?? – marcinj Oct 18 '12 at 01:05
  • or `searchResult`, but then again, it's crazy that the Android source code generates a `NullPointerException` – MarchingHome Oct 18 '12 at 01:09
  • It's crazy that that would be triggered by a onDestroy. Some other method I might understand. I wonder, is there any sort of tear down for the MapView that needs to happen before the onDestroy? I'm just guessing here... – Dr. Cyanide Oct 18 '12 at 04:09

1 Answers1

1

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().

marcinj
  • 48,511
  • 9
  • 79
  • 100