继续运行时异常:在三星设备上的android.view.DisplayListCanvas.throwIfCannotDraw

时间:2018-08-08 08:13:11

标签: android android-view

我在Play商店控制台上发生多次崩溃,我检查了可绘制文件夹中的所有图像,对我来说似乎还可以,因为我怀疑这可能会导致问题。根据报告,它大多在三星设备上崩溃。请指出发生了什么错误。 同样对于背景图片,我正在使用以下尺寸: 分辨率:480 * 800 xhdpi:640 * 960 xxhdpi 1440 * 2560 xxxhdpi:1440 * 2560

`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.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:3128)
at android.view.ViewRootImpl.performDraw (ViewRootImpl.java:2924)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2516)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1515)
at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:7091)
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 (Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run 
(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1410)`.

2 个答案:

答案 0 :(得分:0)

我认为您的例外从这里开始:

protected void throwIfCannotDraw(Bitmap bitmap) {
    if (bitmap.isRecycled()) {
        throw new RuntimeException("Canvas: trying to use a recycled bitmap " + bitmap);
    }
    if (!bitmap.isPremultiplied() && bitmap.getConfig() == Bitmap.Config.ARGB_8888 &&
            bitmap.hasAlpha()) {
        throw new RuntimeException("Canvas: trying to use a non-premultiplied bitmap "
                + bitmap);
    }
    throwIfHwBitmapInSwMode(bitmap);
}

因此,或者您尝试使用回收的位图,或者bmp未预乘,或者您的硬件不支持位图

private void throwIfHwBitmapInSwMode(Bitmap bitmap) {
    if (!mAllowHwBitmapsInSwMode && !isHardwareAccelerated()
            && bitmap.getConfig() == Bitmap.Config.HARDWARE) {
        throw new IllegalStateException("Software rendering doesn't support hardware bitmaps");
    }
}

但我不认为!


因此,现在尝试按以下方式加载图像,以避免出现错误,并通知我:

mImageView.setImageBitmap(decodeSampledBitmapFromResource(getResources(), R.id.myimage, 100, 100));

public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
        int reqWidth, int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(res, resId, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(res, resId, options);
}

对于reference

答案 1 :(得分:0)

最近7天以来,我一直在面对这个问题,解决方案无济于事,只需要检查XML中的所有imageview,其中您特别提到了高度和宽度,而您分配给该视图的可绘制对象太大。