我的应用程序在nougat模拟器和许多设备上工作得非常好,但我在Google Play崩溃记者中发现了这个例外,我不知道为什么会发生这种情况,只有nougat设备才会出现例外情况。
例外:
java.lang.RuntimeException:
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.view.View.getDrawableRenderNode(View.java:18591)
at android.view.View.drawBackground(View.java:18527)
at android.view.View.draw(View.java:18315)
at android.view.View.updateDisplayListIfDirty(View.java:17302)
at android.view.View.draw(View.java:18086)
at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
at android.view.View.updateDisplayListIfDirty(View.java:17297)
at android.view.View.draw(View.java:18086)
at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
at android.view.View.updateDisplayListIfDirty(View.java:17297)
at android.view.View.draw(View.java:18086)
at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
at android.view.View.updateDisplayListIfDirty(View.java:17297)
at android.view.View.draw(View.java:18086)
at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
at android.view.View.updateDisplayListIfDirty(View.java:17297)
at android.view.View.draw(View.java:18086)
at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
at android.view.View.draw(View.java:18327)
at com.android.internal.policy.DecorView.draw(DecorView.java:919)
at android.view.View.updateDisplayListIfDirty(View.java:17302)
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:3135)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2931)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2523)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1522)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7098)
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:0)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
这个错误可能是什么?
注意:我使用的所有drawable都小于 1MB 。
答案 0 :(得分:2)
我在WebView.CanRefresh
上遇到了完全相同的问题。在我的情况下,初始屏幕具有高分辨率,并且错误地将其放置在可绘制的文件夹中。我从this答案中找到了解决方法。
Samsung Galaxy S6 S7 S8
-> drawable
-> New
。 Directory
。如果转到xxhdpi
drawable-xxhdpi
的新文件夹。
res
移到drawable
。答案 1 :(得分:0)
尝试在android.view.DisplayListCanvas.throwIfCannotDraw
中设置调试点,并检查哪个图像引发异常。其中一些是不正确的 - 大尺寸或你有太多的图像,例如,无法记录到画布池。
答案 2 :(得分:0)
仅在我的情况下调整图像大小,我的启动屏幕图像尺寸为1544x2100,所以我更改为1080x2100,这样就可以了! 希望这会有所帮助!!! 谢谢!!!
答案 3 :(得分:0)
private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // 100 MB
@Override
protected void throwIfCannotDraw(Bitmap bitmap) {
super.throwIfCannotDraw(bitmap);
int bitmapSize = bitmap.getByteCount();
if (bitmapSize > MAX_BITMAP_SIZE) {
throw new RuntimeException(
"Canvas: trying to draw too large(" + bitmapSize + "bytes) bitmap.");
}
}
在 DisplayListCanvas 中查看此代码,否则请查看View#draw()方法
boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
boolean drawingWithRenderNode = mAttachInfo != null
&& mAttachInfo.mHardwareAccelerated
&& hardwareAcceleratedCanvas;
···
if (drawingWithRenderNode) {
// Delay getting the display list until animation-driven alpha values are
// set up and possibly passed on to the view
renderNode = updateDisplayListIfDirty();
if (!renderNode.isValid()) {
// Uncommon, but possible. If a view is removed from the hierarchy during the call
// to getDisplayList(), the display list will be marked invalid and we should not
// try to use it again.
renderNode = null;
drawingWithRenderNode = false;
}
}
···
}
为什么我们可以通过取消hardwareAccelerated来解决问题