Some clients experience an app crash directly when they launch it.
Here’s the code of the onCreate() method in the main activity :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String deviceId = Local.getUniqueID(this);
Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(deviceId));
setContentView(R.layout.main);
}
and getUniqueId() does that :
public static String getUniqueID(Context context) {
return Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
}
Is it possible that this call makes the app crash ? May I call this in onCreate() ?
Or is it Thread.setDefaultUncaughtExceptionHandler() that crashes ?
The users who experience this problem don’t even see the splashscreen of the app and I was unable to reproduce the problem on any device I own.
CustomExceptionHandler just get the stack trace of the exception/error and sends it to the server with the device id. I got a device id from a user who experienced the problem and it’s not in the database.
Any idea? I never had that problem along the development on any device. What could be the cause of this? Don’t hesitate to ask for more details.
Thanks
Edit:
I think I found what would be the stacktrace when the application crashes :
E/AndroidRuntime(10067): FATAL EXCEPTION: main
E/AndroidRuntime(10067): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
E/AndroidRuntime(10067): at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
E/AndroidRuntime(10067): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3909)
E/AndroidRuntime(10067): at android.app.ActivityThread.access$1300(ActivityThread.java:122)
E/AndroidRuntime(10067): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1184)
E/AndroidRuntime(10067): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(10067): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(10067): at android.app.ActivityThread.main(ActivityThread.java:4340)
E/AndroidRuntime(10067): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(10067): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(10067): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(10067): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(10067): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(10067): Caused by: java.lang.NullPointerException
E/AndroidRuntime(10067): at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
E/AndroidRuntime(10067): at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
E/AndroidRuntime(10067): at android.app.LoadedApk.makeApplication(LoadedApk.java:474)
E/AndroidRuntime(10067): ... 11 more
I believe that
can return null on some devices.
So you end up calling
which causes your crash.
This could be confirmed if you attached a crash log.