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

继续运行时异常:三星设备上的android.view.DisplayListCanvas.throwIfCannotDraw,android,android-view,Android,Android View,我在play store控制台上有多个崩溃,我已经检查了drawable文件夹中的所有图像,对我来说似乎没有问题,因为我怀疑这可能会导致问题。据报道,它主要是在三星设备上崩溃。请说明发生了什么错误。 对于背景图像,我也使用此尺寸: hdpi:480*800 xhdpi:640*960 xxhdpi 1440*2560 xxxhdpi:1440*2560 `at android.view.DisplayListCanvas.throwIfCannotDraw (DisplayListCanvas

我在play store控制台上有多个崩溃,我已经检查了drawable文件夹中的所有图像,对我来说似乎没有问题,因为我怀疑这可能会导致问题。据报道,它主要是在三星设备上崩溃。请说明发生了什么错误。 对于背景图像,我也使用此尺寸: hdpi: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)`.

我认为你的例外情况从这里开始:

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);
}

对于。

从过去7天开始,我一直面临这个问题,解决方案只是需要检查所有XML格式的imageview,其中您特别提到了高度和宽度,并且分配给该视图的可绘制视图太大。

是否都是os 4.x版本?它主要在android 7.0上。您的应用程序使用什么扩展背景图像?他们的尺寸单位是MB?我使用的尺寸是:hdpi:480*800 xhdpi:640*960 xxhdpi 1080*1920 xxxhdpi:1440*2560,尺寸单位是KB。希望你是说这个问题是我在play store上得到这个日志,我在多个地方设置背景图像,所以我不知道在哪里写上面的代码。只需在所有地方写这个代码。这使您的代码更快,内存消耗更少!