[英]NullPointerExceptions only on some Samsung Galaxy devices?
I'm using LibGDX. 我正在使用LibGDX。 When my app starts, it creates a Screen.
当我的应用启动时,它将创建一个屏幕。 When the Screen is loaded, it calls a static function
Module.createStyles()
. 加载Screen时,它将调用静态函数
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). 此函数创建了一系列样式,这些样式将在应用程序的其余部分中使用(内置的LibGDX样式,例如WindowStyle,LabelStyle,TextButtonStyle-用于创建用户界面对象的所有类型的东西)。
When the Screen is done, it calls Module.disposeStyles()
. 完成屏幕后,它将调用
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 : 无论如何,根据我的Google Analytics(分析)崩溃报告,例如,尝试使用Module.dialogStyle创建Dialog时,我会随机获得NullPointerException :
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. 绝对没有理由Module.dialogStyle应该为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). 我将此字段
Module.disposeStyles()
null的唯一位置是在Module.disposeStyles()
并且仅在应用程序的一个特定位置(最后)调用此函数。
I would assume this was a bug in my code somehow even though 95% of users never experience it. 我会假设这是我代码中的错误,即使95%的用户从未遇到过。 However, all 5% that do experience it seem to be Galaxy users and I'm not sure if that's a coincidence:
但是,所有5%确实经历过体验的人似乎都是Galaxy用户,而且我不确定这是否是巧合:
Anyone have any ideas? 有人有想法么? Don't Galaxy devices have a built-in RAM manager?
Galaxy设备没有内置的RAM管理器吗? 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. 是对
Module
类的static
属性的引用。
You are probably running into side-effects of how Android manages the life-cycle of JVMs. 您可能会遇到Android如何管理JVM生命周期的副作用。 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).
在某些情况下(尤其是在较大的设备上),将重新使用JVM实例可能会导致问题(例如,静态初始化程序已经运行,并且不会重新运行)。 Alternatively,
static
pointers may live from a previous run of your application into the next, and may have invalid or incorrect state in them. 另外,
static
指针可能从您的应用程序的上一次运行到下一次运行,并且可能具有无效或不正确的状态。 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/ 有关不同生命周期以及如何在本地复制它们的更多详细信息,请参见: http : //bitiotic.com/blog/2013/05/23/libgdx-and-android-application-lifecycle/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.