问题
I am having multiple crashes on play store console, I have checked all images in the drawable folder and it seems to be fine to me as I suspect this can cause the issue. It is mostly crashing on samsung devices as per report. Please suggest what wrong is happening. Also for background images I am using this size: 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)`.
回答1:
I think that your Exception starts from here:
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);
}
So or you are trying to use a recycled bitmap or your bmp is not premultiplied or your hardware does'nt support bitmaps
private void throwIfHwBitmapInSwMode(Bitmap bitmap) {
if (!mAllowHwBitmapsInSwMode && !isHardwareAccelerated()
&& bitmap.getConfig() == Bitmap.Config.HARDWARE) {
throw new IllegalStateException("Software rendering doesn't support hardware bitmaps");
}
}
but i don't think!
SO now try to load images as follow to avoid errors and let me know:
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);
}
For reference.
回答2:
I have been facing this issue from last 7 days and the solution is nothing but just need to check all imageview in XML where you specifically mentioned height and width and the drawable which you are assigning to that view is too large.
来源:https://stackoverflow.com/questions/51741718/continues-runtime-exception-android-view-displaylistcanvas-throwifcannotdraw-o