java - Android Drawing Bitmap Causes Null Pointer Exception -



java - Android Drawing Bitmap Causes Null Pointer Exception -

i'm trying draw bitmap nullpointerexception...

crab1 = bitmapfactory.decoderesource(this.getresources(), r.drawable.ic_launcher); // in draw method canvas.drawbitmap(crab1, screenw / 2, screenh - 2 * rowheight, null);

it gives error message:

java.lang.nullpointerexception @ android.graphics.canvas.throwifcannotdraw(canvas.java:1083) @ android.graphics.canvas.drawbitmap(canvas.java:1139) @ com.coderogden.crabber.titleview.draw(titleview.java:100) @ android.view.view.draw(view.java:14501) @ android.view.viewgroup.drawchild(viewgroup.java:3102) @ android.view.viewgroup.dispatchdraw(viewgroup.java:2939) @ android.view.view.draw(view.java:14619) @ android.view.view.draw(view.java:14501) @ android.view.viewgroup.drawchild(viewgroup.java:3102) @ android.view.viewgroup.dispatchdraw(viewgroup.java:2939)

edited:

as @throwaway pointed out, paint can null, , since exception started within throwifcannotdraw, suppose null reference bitmap, since:

protected static void throwifcannotdraw(bitmap bitmap) { if (bitmap.isrecycled()) { throw new runtimeexception("canvas: trying utilize recycled bitmap " + bitmap); } if (!bitmap.ispremultiplied() && bitmap.getconfig() == bitmap.config.argb_8888 && bitmap.hasalpha()) { throw new runtimeexception("canvas: trying utilize non-premultiplied bitmap " + bitmap); } }

so might same issue android: bitmapfactory.decoderesource returning null

java android bitmap nullpointerexception

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -