Android 强制关闭特定图像上的应用程序。我如何追踪问题?

发布于 2024-12-10 03:19:05 字数 2782 浏览 0 评论 0 原文

我正在尝试在画布上显示 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

I'm trying to display 2 images on a canvas. I've loaded one, and it works fine. The second I've created, loaded and am displaying in the same manner, but the app force closes each time.

Both images are PNGs and are in res/drawable-mdpi.

Loading images:

private Bitmap stageBMP=BitmapFactory.decodeResource(getResources(), R.drawable.stagel);
private Bitmap magBMP = BitmapFactory.decodeResource(getResources(), R.drawable.mag);

Displaying images:

canvas.drawBitmap(stageL, 300,300, null);
canvas.drawBitmap(magBMP, 300,300, null);

If I comment out the final line, the app loads (displaying only the first image). Instead of displaying magBMP I show stageL twice, it works.

Working image:

Working image

Incompatible image:

Incompatible image

Stacktrace:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

场罚期间 2024-12-17 03:19:05

好的,我设法找到了解决方案。

我没有在一个类中加载图像并将它们传递给另一个类来显示,而是将上下文传递给第二个类,然后加载它们并在那里显示它们。

我承认我不太明白为什么这应该起作用,但对于一个杂乱的解决方案来说,它现在就可以了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文