我是android的新手,但是我有这个,我的应用在部署时崩溃了
public class DungeonExplorer extends View {
private int CHIBI_SIZE = 125;
Bitmap chibiSprite;
Rect sourceRect;
Rect destinationRect;
Paint emptyPaint = new Paint();
public DungeonExplorer(Context context) {
super(context);
init();
}
private void init(){
chibiSprite = BitmapFactory.decodeResource(getResources(), R.drawable.chibi_sprite);
sourceRect = new Rect(0, 2* CHIBI_SIZE, CHIBI_SIZE, 3* CHIBI_SIZE);
destinationRect = new Rect(100, 100, 500, 500);
}
@Override
protected void onDraw(Canvas canvas) {
drawCharacter(canvas);
}
private void drawCharacter(Canvas canvas){
canvas.drawBitmap(chibiSprite, sourceRect, destinationRect, emptyPaint);
}
问题出在方法drawCharacter / onDraw上,我不确定我在做什么错
正在运行的错误消息:java.lang.NullPointerException
答案 0 :(得分:0)
The View
class has many constructors. Be sure you override all constructors and use init()
in all of them