Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Continues Runtime Exception : android.view.DisplayListCanvas.throwIfCannotDraw on samsung devices

Ask Question

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)`.
                Dimension I am using is  I am using this size: hdpi :480*800 xhdpi: 640*960 xxhdpi 1080*1920 xxxhdpi: 1440*2560 and size is in KB. Hope you mean this
– sharma.mahesh369
                Aug 10, 2018 at 9:09

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.

the problem is I am getting this log on play store and I am setting background image at multiple places so I don't know where to write the above piece of code. – sharma.mahesh369 Aug 10, 2018 at 9:05 Simply write this code in all the places. This make your code faster and less-memory-consumer! – Roberto Manfreda Aug 10, 2018 at 9:06

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.