I'm using LibGDX. When my app starts, it creates a Screen. When the Screen is loaded, it calls a static function Module.createStyles()
.
This function creates a bunch of styles that will be used throughout the rest of the application (built-in LibGDX styles like WindowStyle, LabelStyle, TextButtonStyle - all of the types of things used to create the user-interface objects).
When the Screen is done, it calls Module.disposeStyles()
.
Anyway, according to my Google Analytics crash reports, I randomly get a NullPointerException when trying to, for example, create a Dialog with Module.dialogStyle:
ExitDialog exitDialog = new ExitDialog("Are you sure?", Module.dialogStyle);
Thread: GLThread 2089, Exception: java.lang.IllegalArgumentException: style cannot be null.
at package.Window.setStyle(Window.java:181)
at package.Window.<init>(Window.java:63)
at package.Dialog.<init>(Dialog.java:65)
at package.ExitDialog$1.<init>(ExitDialog.java:38)
There is absolutely no reason Module.dialogStyle should be null. The only place I null this field is in Module.disposeStyles()
and this function is only called in one specific place in the application (at the very end).
I would assume this was a bug in my code somehow even though 95% of users never experience it. However, all 5% that do experience it seem to be Galaxy users and I'm not sure if that's a coincidence:
Anyone have any ideas? Don't Galaxy devices have a built-in RAM manager? Would that have something to do with this?
I'm going to assume that:
Module.dialogStyle
is a reference to a static
property on the Module
class.
You are probably running into side-effects of how Android manages the life-cycle of JVMs. There are scenarios (especially on bigger devices) where a JVM instance will be re-used that can cause problems (static initializers will have already been run, for example, and will not re-run). Alternatively, static
pointers may live from a previous run of your application into the next, and may have invalid or incorrect state in them. It depends on the particulars of how your app is organized.
If you include more of the code that shows how and when you initialize the static fields, we can probably figure it out.
For more details on the different lifecycles and how to reproduce them locally, see: http://bitiotic.com/blog/2013/05/23/libgdx-and-android-application-lifecycle/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With