NullPointerExceptions on select Samsung Galaxy devices only?

I am using LibGDX. When my application starts, it creates a screen. When the screen is loaded, it calls the static function Module.createStyles() .

This function creates a bunch of styles that will be used throughout the rest of the application (LibGDX built-in styles such as WindowStyle, LabelStyle, TextButtonStyle - all types of objects that are used to create user interface objects).

When the screen is done, it calls Module.disposeStyles() .

In any case, according to my Google Analytics crash reports, I accidentally get a NullPointerException when I try, for example, to 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 why Module.dialogStyle should be null. The only place where I null this field is in Module.disposeStyles() , and this function is called only in one specific place of the application (at the very end).

I would suggest that this was a mistake in my code, although 95% of users have never experienced this. However, all 5% that they really experience seem to be Galaxy users, and I'm not sure if this is a coincidence:

  • Galaxy S4
  • Galaxy S III
  • GALAXY Tab 3 lite

Does anyone have any ideas? Galaxy devices don't have a built-in RAM manager? Will this have anything to do with this?

+5
source share
1 answer

I am going to assume that:

 Module.dialogStyle 

is a reference to the static property in the Module class.

You've probably come across side effects of how Android manages the JVM life cycle. There are scenarios (especially on larger devices) where the JVM instance will be reused, which can cause problems (for example, static initializers have already been executed and they will not restart). Alternatively, static pointers may live from the previous launch of your application to the next and may have an invalid or incorrect state in them. It depends on the organization of your application.

If you include more code that shows how and when you initialize static fields, we can probably figure it out.

For more information about the different life cycles and how to reproduce them locally, see http://bitiotic.com/blog/2013/05/23/libgdx-and-android-application-lifecycle/

+4
source

Source: https://habr.com/ru/post/1201847/


All Articles