我正在绘制的图片太大而且它会杀死我的应用程序。
发生以下错误:
java.lang.RuntimeException: Canvas: trying to draw too large (numbernumbernumberbytes) bitmap.
我已经浏览了我的应用,并且已禁用所有直接加载的大图像。使用Glide(图像加载库,https://github.com/bumptech/glide)加载的图像应该不是问题。
错误仍然存在,我想知道是否有办法追踪错误。要确切了解导致问题的图像。
有没有办法追踪这个?
EDIT1:
错误的完整堆栈跟踪:
07-07 19:22:21.468 D/AndroidRuntime: Shutting down VM
--------- beginning of crash
07-07 19:22:21.469 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.linkhubapp, PID: 20097
java.lang.RuntimeException: Canvas: trying to draw too large(132710400bytes) bitmap.
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
at android.graphics.Canvas.drawBitmap(Canvas.java:1420)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:545)
at android.widget.ImageView.onDraw(ImageView.java:1286)
at android.view.View.draw(View.java:18318)
at android.view.View.updateDisplayListIfDirty(View.java:17296)
at android.view.View.draw(View.java:18080)
at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
at android.view.View.updateDisplayListIfDirty(View.java:17291)
at android.view.View.draw(View.java:18080)
at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
at android.view.View.updateDisplayListIfDirty(View.java:17291)
at android.view.View.draw(View.java:18080)
at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
at android.view.View.updateDisplayListIfDirty(View.java:17291)
at android.view.View.draw(View.java:18080)
at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
at android.view.View.updateDisplayListIfDirty(View.java:17291)
at android.view.View.draw(View.java:18080)
at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
at android.view.View.draw(View.java:18321)
at com.android.internal.policy.DecorView.draw(DecorView.java:919)
at android.view.View.updateDisplayListIfDirty(View.java:17296)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:692)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:698)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:806)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3121)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2917)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2509)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1508)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7084)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
at android.view.Choreographer.doCallbacks(Choreographer.java:702)
at android.view.Choreographer.doFrame(Choreographer.java:638)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
答案 0 :(得分:1)
(我正在使用Android Studio)...要知道它是哪张图像,需要进行少量调试。请执行以下操作:
单击链接应突出显示一行代码,可能如下:
canvas.drawBitmap(bitmap,null,mDstRect,paint);
在该行代码上设置一个断点。然后使用“调试应用程序”按钮再次运行该应用程序。该程序将在上面的代码行停止。您需要单击“恢复程序”按钮,并跟踪在程序崩溃之前单击该按钮的次数。然后再次在调试模式下运行该应用程序,使其在该行代码上中断,然后单击“恢复程序”按钮,您之前单击该按钮的次数减一次。因此,如果我单击“恢复程序”按钮4次进入崩溃,则需要单击3次并在此处停止。这将是导致应用崩溃的代码的执行时间。
该行代码的断点应该被击中并且程序停止运行,为您做点准备。将鼠标悬停在代码行中的“位图”一词上
canvas.drawBitmap(bitmap,null,mDstRect,paint);
不要将鼠标悬停在“ drawBitmap”一词上,而只需将鼠标悬停在“ bitmap”一词上。在包含加号(+)和“ {Bitmap @ ####}”的代码行下方应出现一个黄色的小窗口。单击加号。请注意,显示的第一行文字的最右边是一个可点击的链接,显示为“查看位图”。单击该链接,您应该看到该应用正在尝试且无法加载的图片。
就是这样!