0

I've released an app which uses the Android Compatibility Library for Google Maps (https://github.com/petedoyle/android-support-v4-googlemaps) and I've received some odd "Unable to start activity" crash reports.

I've pasted a couple of sample stack traces below. Anyone else experienced this using the Android Compatibility Library for Google Maps or even using the standard Android Compatibility Library (http://developer.android.com/sdk/compatibility-library.html)? Anyone know how I might be able to overcome this error?

----- Example stack trace 1 -----

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycompany.myapp/com.mycompany.myapp.activities.GameActivity}: java.lang.NullPointerException
...
caused by java.lang.NullPointerException
 at android.app.ContextImpl.openFileOutput(ContextImpl.java:430)
 at android.content.ContextWrapper.openFileOutput(ContextWrapper.java:158)
 at com.google.common.io.android.AndroidPersistentStore.writeBlockX(Unknown Source)
 at com.google.common.io.android.AndroidPersistentStore.writeBlock(Unknown Source)
 at com.google.common.io.PreferenceStore.ensurePreferencesLoaded(Unknown Source)
 at com.google.common.io.PreferenceStore.readPreference(Unknown Source)
 at com.google.common.io.BasePersistentStore.readPreference(Unknown Source)
 at com.google.common.StaticUtil.readPreferenceAsDataInput(Unknown Source)
 at com.google.googlenav.datarequest.DataRequestDispatcher.loadOrRequestCookie(Unknown Source)
 at com.google.googlenav.datarequest.DataRequestDispatcher.<init>(Unknown Source)
 at com.google.googlenav.datarequest.DataRequestDispatcher.createInstance(Unknown Source)
 at com.google.android.maps.MapActivity.createMap(MapActivity.java:509)
 at com.google.android.maps.MapActivity.onCreate(MapActivity.java:409)
 at android.support.v4.app.FragmentActivity.onCreate(Unknown Source)
 at com.mycompany.myapp.activities.GameActivity.onCreate(Unknown Source)
 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

----- Example stack trace 2 -----

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycompany.myapp/com.mycompany.myapp.activities.GameActivity}: java.lang.NullPointerException
...
Caused by: java.lang.NullPointerException
 at android.app.ContextImpl.openFileOutput(ContextImpl.java:423)
 at android.content.ContextWrapper.openFileOutput(ContextWrapper.java:158)
 at android_maps_conflict_avoidance.com.google.common.io.android.AndroidPersistentStore.writeBlockX(AndroidPersistentStore.java:140)
 at android_maps_conflict_avoidance.com.google.common.io.android.AndroidPersistentStore.writeBlock(AndroidPersistentStore.java:169)
 at android_maps_conflict_avoidance.com.google.common.io.PreferenceStore.ensurePreferencesLoaded(PreferenceStore.java:178)
 at android_maps_conflict_avoidance.com.google.common.io.PreferenceStore.readPreference(PreferenceStore.java:86)
 at android_maps_conflict_avoidance.com.google.common.io.BasePersistentStore.readPreference(BasePersistentStore.java:41)
 at android_maps_conflict_avoidance.com.google.common.StaticUtil.readPreferenceAsDataInput(StaticUtil.java:271)
 at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.loadOrRequestCookie(DataRequestDispatcher.java:493)
 at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.<init>(DataRequestDispatcher.java:390)
 at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.createInstance(DataRequestDispatcher.java:341)
 at com.google.android.maps.MapActivity.createMap(MapActivity.java:548)
 at com.google.android.maps.MapActivity.onCreate(MapActivity.java:422)
 at android.support.v4.app.FragmentActivity.onCreate(Unknown Source)
 at com.mycompany.myapp.activities.GameActivity.onCreate(Unknown Source)
 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1709)
Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
  • Share your GameActivity.java Source code!1 – Vipul Jun 15 '12 at 17:09
  • Buried down in both stack traces, there is an 'UnknownSource' exception on your 'onCreate' for GameActivity (which is your main activity, my guess). Check your 'onCreate' method to see if something is missing its source. – gsb Jun 15 '12 at 17:11
  • My `GameActivity` extends `android.support.v4.app.FragmentActivity` which extends `com.google.android.maps.MapActivity`. The first line of my `GameActivity.onCreate(Bundle savedInstanceState)` method is `super.onCreate(savedInstanceState);`. Judging from the stack trace this line seems to be the culprit... – Adil Hussain Jun 15 '12 at 17:33
  • can you post your GameActivity? – gsb Jun 15 '12 at 17:57

2 Answers2

1

I have the same bug and it seems that this error has no link with the usage of android-support-v4-googlemaps.

Take a look at this post :

MapView / MapActivity crash on some devices

Community
  • 1
  • 1
Quentin G.
  • 988
  • 9
  • 15
  • I think you're right that the bug has no linkage with the support library directly. As for the post you linked to, unfortunately that's not the solution for me (my package name does start with a `com.`). – Adil Hussain Mar 08 '13 at 17:50
  • Have you put that line in the manifest's `` and if you use a MapView did you name it as such : ` – Quentin G. Mar 11 '13 at 13:56
  • Otherwise it might be a problem with your API key, you must generate a key based on your debug key (in debug.keystore) for testing purposes as described in this link : [obtaining api key v1](https://developers.google.com/maps/documentation/android/v1/mapkey) – Quentin G. Mar 11 '13 at 14:07
  • At last (and this is very important) it might also be a problem with your `onCreate` function : you must have the `super.onCreate(savedInstanceState);` **BEFORE** the `setContentView(R.layout.activity_my_activity);`. In fact try to call the super.onCreate first of all. – Quentin G. Mar 11 '13 at 15:07
  • Thanks for the tips Quentin. Appreciate it. I have all those things in place and my app runs fine on all the Android devices that I have. It seems to be falling over on only some Android devices (which I don't have). So very hard to get to the bottom of! – Adil Hussain Mar 12 '13 at 08:37
0

I had this error when I used the compatibility library. What I had was the project which targeted Android API 15, but I wanted the minimum version to be Android API 8, so I needed a few things from the compatibility library. I have attached the library, but forgot to use imports from it! When project was built, it was perfectly fine, but when I runned it on my phone which had Android 2.3.3 on it, it couldn't find some classes, because Android 2.3.3 just didn't have them! So, I suggest you to delete all imports, press Ctrl+Shift+O and whenever there will be a choice to use a normal Android build-in class or one from the compatibility library, always choose the second one. Tell me if it helped!

lomza
  • 9,412
  • 15
  • 70
  • 85
  • I wish that was it! But I've double checked (by setting my build target to API 8) and I have all the correct imports. I'm guessing from the infrequency of the error reports I'm receiving that these errors are happening on some phones only. Just so annoying not being able to replicate it on the phones I have. Curious to know if others have had similar problems with the compatibility libraries... – Adil Hussain Jun 18 '12 at 10:49
  • 1
    I have this error as well. I am using the emulator. Target is Google APIs, API 10. – bhekman Jun 20 '12 at 01:33