Android 强制关闭特定图像上的应用程序。我如何追踪问题?
我正在尝试在画布上显示 2 个图像。我已经加载了一个,效果很好。我创建、加载并以相同方式显示第二个,但应用程序每次都会强制关闭。
两个图像都是 PNG,并且位于 res/drawable-mdpi 中。
加载图像:
private Bitmap stageBMP=BitmapFactory.decodeResource(getResources(), R.drawable.stagel);
private Bitmap magBMP = BitmapFactory.decodeResource(getResources(), R.drawable.mag);
显示图像:
canvas.drawBitmap(stageL, 300,300, null);
canvas.drawBitmap(magBMP, 300,300, null);
如果我注释掉最后一行,应用程序将加载(仅显示第一张图像)。我没有显示 magBMP
,而是显示了 stageL
两次,它有效。
工作图像:
不兼容图像:
堆栈跟踪:
10-17 19:23:03.233: DEBUG/RobotronActivity(746): View added
10-17 19:23:03.403: DEBUG/MainThread(746): Starting game loop
10-17 19:23:03.543: WARN/dalvikvm(746): threadid=9: thread exiting with uncaught exception (group=0x40014760)
10-17 19:23:03.543: ERROR/AndroidRuntime(746): FATAL EXCEPTION: Thread-10
10-17 19:23:03.543: ERROR/AndroidRuntime(746): java.lang.NullPointerException
10-17 19:23:03.543: ERROR/AndroidRuntime(746): at android.graphics.Canvas.throwIfRecycled(Canvas.java:999)
10-17 19:23:03.543: ERROR/AndroidRuntime(746): at android.graphics.Canvas.drawBitmap(Canvas.java:1040)
10-17 19:23:03.543: ERROR/AndroidRuntime(746): at com.cjs.robotron.Droid.draw(Droid.java:28)
10-17 19:23:03.543: ERROR/AndroidRuntime(746): at com.cjs.robotron.MainGamePanel.onDraw(MainGamePanel.java:108)
10-17 19:23:03.543: ERROR/AndroidRuntime(746): at com.cjs.robotron.MainThread.run(MainThread.java:52)
10-17 19:23:03.566: WARN/ActivityManager(73): Force finishing activity com.cjs.robotron/.RobotronActivity
10-17 19:23:03.566: WARN/WindowManager(73): Failure taking screenshot for (216x135) to layer 21020
10-17 19:23:04.073: WARN/ActivityManager(73): Activity pause timeout for ActivityRecord{407afbf0 com.cjs.robotron/.RobotronActivity}
10-17 19:23:04.213: WARN/InputManagerService(73): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@406a7738 (uid=10036 pid=746)
10-17 19:23:04.223: WARN/InputManagerService(73): Client not active, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40eefcf8
10-17 19:23:04.913: INFO/ActivityManager(73): Displayed com.cjs.robotron/.RobotronActivity: +3s510ms
10-17 19:23:10.893: DEBUG/dalvikvm(221): GC_EXPLICIT freed 18K, 5% free 6274K/6599K, paused 3ms+3ms
10-17 19:23:14.797: WARN/ActivityManager(73): Activity destroy timeout for ActivityRecord{407afbf0 com.cjs.robotron/.RobotronActivity}
10-17 19:23:15.973: DEBUG/dalvikvm(325): GC_EXPLICIT freed 8K, 6% free 6198K/6531K, paused 3ms+3ms
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我设法找到了解决方案。
我没有在一个类中加载图像并将它们传递给另一个类来显示,而是将上下文传递给第二个类,然后加载它们并在那里显示它们。
我承认我不太明白为什么这应该起作用,但对于一个杂乱的解决方案来说,它现在就可以了。
OK, I managed to find a solution.
Instead of loading images in one class and passing them to another to be displayed, I passed the context to the second class, and loaded them and displayed them there.
I confess I don't really understand why this should work, but for a scrappy solution it'll do for now.