Error android.graphics.Canvas.throwIfRecycled when applying raster images

I am trying to overlay images on a canvas using the following method:

private Bitmap overlay(Bitmap bmp1, Bitmap bmp2) { bmOverlay = Bitmap.createBitmap(70, 70, Bitmap.Config.RGB_565); canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1, 0, 0, null); //line 179 canvas.drawBitmap(bmp2, 0, 0, null); return bmOverlay; } 

However, my application continues to crash and the log reads:

java.lang.NullPointerException at android.graphics.Canvas.throwIfRecycled (Canvas.java:954) on android.graphics.Canvas.drawBitmap (Canvas.java:980) at com.MyApp.overlay (MyApp.java:179)

Can anyone help?

+7
android nullpointerexception bitmap canvas
source share
3 answers

I had the same trowIfRecycled exception when trying to draw a bitmap on canvas. I tried to draw a stream, which I started before the program began to initialize the bitmap. So in my case: the bitmap was zero, and I had to look for a better place to initialize.

+4
source share

Although this is on an old question, I found this solution to be for me. http://nowherenearithaca.blogspot.com/2011/06/solved-bizarre-null-pointer-thrown-in.html

where do they offer

Try to make a clean eclipse. It seems to be cached sometimes and can get confused. This seemed to solve it for this particular case.

+2
source share

I also had the same stack trace, and I tried to find a solution from threads, etc. But then I found out that I never assigned a bitmap variable in my code.

0
source share

All Articles