32

My application work very well on nougat emulator and many devices, but i found this exception in google play crash reporter, I don't know why it happened, The exception causes with nougat devices ++ only.

the exception :

   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)

What this error could be?

CAUTION: all drawable i used is less than 1MB.

tech star
  • 25
  • 5
  • 9
    I have the exact same problem with samsung galaxy s6 s7 and s8. If u find a solution please share it with us – Ramdane Oualitsen Mar 01 '18 at 10:05
  • i had the same issue try this link and you may save so much time in searching for solution https://stackoverflow.com/questions/39111248/canvas-trying-to-draw-too-large-bitmap-when-android-n-display-size-set-larger – Divyanshu Kumar Mar 16 '20 at 14:47

6 Answers6

25

I had the exact same problem with Samsung Galaxy S6 S7 S8. In my case Splash Screen had high resolution and it was mistakenly placed in the drawable folder. I found solution from this answer.

  1. Right Click on drawable -> New -> Directory.
  2. Enter new directory name: xxhdpi. It will create a new folder named drawable-xxhdpi if you go to res
  3. Move your splash image from drawable to drawable-xxhdpi.
Shuvo Joseph
  • 894
  • 1
  • 12
  • 21
  • I am getting the same issue on Samsung S7 and J7 and I have tried this solution. But still getting the same error. – Aashish Kumar Jul 27 '20 at 12:22
  • This logic solved the issue in my case for Samsung S6 with Sdks 21, 22, 23 and 24, 1440x2560 and 640 dpi (xxxhdpi). I created a drawable-xxxhdpi and put the splash image there. – lubrum Dec 23 '20 at 14:37
5

Just Resize your image in my case my Splash screen image dimensions are 1544x2100 so i changed to 1080x2100 and that will work!! Hope this will help!!! Thanks!!!

Divyaraj
  • 63
  • 1
  • 5
2

Try to set a debug point in android.view.DisplayListCanvas.throwIfCannotDraw and check what image is throw an exception. Some of them is incorrect - large size or you have too many images for example and cant record to canvas pool.

mzherdev
  • 462
  • 1
  • 4
  • 11
  • I don't have much images, and i can't debug on this method. –  Jul 05 '17 at 07:56
  • after debug on other method i found this bitmap : `android.graphics.bitmap@7od1086` –  Jul 05 '17 at 08:07
  • Is your images in _drawable_ folder? Try to move on _drawable_hdpi_ folder. It can help. Check this link: https://stackoverflow.com/questions/39111248/canvas-trying-to-draw-too-large-bitmap-when-android-n-display-size-set-larger – mzherdev Jul 05 '17 at 08:28
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.");
        }
    }

See this code in DisplayListCanvas,otherwise look at View#draw() method,

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

that why we can resolve the problem by cancel the hardwareAccelerated

Victor
  • 1
  • 1
    Disabling hardwareAccelerated could cause other problems and performance issues that can affect user experience and interface. – lubrum Dec 23 '20 at 14:15
0

To anyone who still needs an answer to this question(as I did two days ago) the answer is simple: Resize all your images that are above 1024 x 1024 to 1024 x 1024, for example I had an image with something like 1080 x 850, that 1080 is a problem and would thus need to be resized and scaled down to 1024 and if you use a photo editing tool, when scaling it will automatically set the correct width / length to your image

Peter Aoun
  • 19
  • 3
0

Just an addition to the Shuvo Joseph's answer, maybe it's a good idea to not only add drawable-xxhdpi density folder, but also add another density folder.
So whatever the android version and size, your app can prepare the image source with the right size :

  1. Change your folder view on the top left from Android to Project
  2. Go to YourProjectFolder folder > app > src > main > res
  3. Prepare the original image with your best resolution, and split it into each folder size automatically. You can do it in Baker
  4. Then create a folder with another density, namely:
  5. drawable-hdpi, drawable-ldpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi, drawable-xxxhdpi
  6. Put each image into the appropriate folder
Muhammad Faisal
  • 734
  • 10
  • 24