android - "Something wrong here, didn' t expect PACKAGE to be resumed"android Logcat 中的错误

标签 android crash orientation nullpointerexception logcat

我有一个仿照 Google 的 LunarLander 示例的 Android 应用程序。我正在使用 Android 2.0 的真实设备 (Motorola Droid) 对其进行调试。当方向改变时,程序会因 NullPointerException 而崩溃。崩溃前的 Logcat:

02-01 00:24:27.956: DEBUG/nate(8358): Starting Game
02-01 00:24:36.878: DEBUG/dalvikvm(1086): GC freed 1788 objects / 92256 bytes in 1389ms
02-01 00:24:38.542: INFO/WindowManager(1021): Setting rotation to 1, animFlags=0
02-01 00:24:38.558: INFO/ActivityManager(1021): Config changed: { scale=1.0 imsi=310/4 loc=en_US touch=3 keys=2/1/2 nav=2/2 orien=2 layout=34}
02-01 00:24:38.620: WARN/UsageStats(1021): Something wrong here, didnt expect org.nifong.leeder to be resumed
02-01 00:24:38.886: DEBUG/nate(8358): New Surface dimensions: 854x442
02-01 00:24:38.886: DEBUG/nate(8358): flies was null

让我担心的第一行是 “Something wrong here” at 24:38.620。我不知道这是什么意思,但我认为这是因为我没有对屏幕变化做出正确的 react 。

接下来,我收到一条调试消息,该消息是我从自己的方法 surfaceChanged() 中打印出来的,关于新的表面尺寸。

然后我打印出有关 flies 是否为 null 的调试消息。 flies 是最终导致 NullPointerException 的字段。它被创建一次,并且再也不会为程序的其余部分写入。我知道它在崩溃之前不是空的,因为它被读取了好几次。

有没有人知道我的私有(private)成员变量是如何通过这些线索变为 null 的?

我会包含代码,但代码很多,我不知道哪些是相关的。

最佳答案

Android 中的方向变化会影响状态。基本上,您的 Activity 被销毁并重新创建。因此,您必须知道什么 Android lifecycle将调用事件以及如何保存状态。

您还需要警惕 static 实例以及它如何影响此生命周期。

Here is a blog post解释其中的一些内容。

关于android - "Something wrong here, didn' t expect PACKAGE to be resumed"android Logcat 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2174865/

相关文章:

ios - 应用程式当机UIFoundation:UINibDecoderDecodeObjectForValue + 424

python - 尝试创建列表时python crashes(?)

android - 主题中的自定义项目

android - Google PlacePicker 在启动后立即关闭,结果代码为 2

Android - 如何处理超时

ios - 如何在UIDeviceOrientationIsPortrait中设置iPhone App的方向?

ios - 全屏查看图片时解锁方向

javascript - 如何在桌面浏览器上模拟移动设备陀螺仪(deviceorientation 事件)以进行调试?

android - 尝试加载资源时,MediaMetadataRetriver.setDataSource在发行时崩溃(状态= 0x80000000)

javascript - 在 Titanium 应用程序中嵌入远程网站的一些内容