在Canvas

时间:2018-03-25 12:36:21

标签: java android bitmap nullpointerexception android-bitmap

我试图在Canvas上绘制一个位图,但我得到了一个我不明白的NullPointerException。代码和错误如下:

代码:

Bitmap android_guy;
android_guy = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(context.getResources(),R.mipmap.ic_launcher),50,50, true);
canvas.drawBitmap(android_guy, width/2, 0, null);

错误:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:702)

0 个答案:

没有答案