我试图在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)