-1
私は、ユーザーが画面上に描画できる単純な描画ビューを作成しようとしています。しかし、数時間の研究の後、私はまだ私のonDraw()メソッドでcanvas.drawPath()を呼び出すと、アプリがクラッシュする理由を解決するのに問題があるようです。お時間をnull canvas.drawPath()へのポインタ
FATAL EXCEPTION: main
Process:
com.ting.cian.ting, PID: 7989
java.lang.NullPointerException: Attempt to read from field 'boolean
android.graphics.Path.isSimplePath' on a null object reference
at
android.graphics.BaseCanvas.drawPath(BaseCanvas.java:295)
at
android.graphics.Canvas.drawPath(Canvas.java:1652)
at
com.ting.cian.ting.DrawTing.onDraw(DrawTing.java:124)
at
android.view.View.draw(View.java:19119)
at
android.view.View.updateDisplayListIfDirty(View.java:18069)
at
android.view.View.draw(View.java:18847)
at
android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at
android.view.View.updateDisplayListIfDirty(View.java:18060)
at
android.view.View.draw(View.java:18847)
...
ありがとう:私のlogcatは、このエラーメッセージが表示されている
public class DrawTing extends View{
private Bitmap bm;
private Canvas canv;
private Path path;
Context context;
private Paint paint1;
private Paint paint;
public DrawTing(Context c) {
super(c);
this.context = c;
}
public DrawTing(Context c, AttributeSet attrs) {
super(c, attrs);
this.context = c;
}
public DrawTing(Context c, AttributeSet attrs, int defStyle) {
super(c, attrs, defStyle);
this.context = c;
path = new Path();
paint = new Paint();
paint.setDither(true);
paint.setAntiAlias(true);
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeWidth(10f);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
canv = new Canvas(bm);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawPath(path, paint); //NPE here
//Things I have tried along with canvas.drawPath()
//canvas = this.canv
//canvas = canv;
//canvas = new Canvas();
//canvas.drawRect(0,0, getWidth(), getHeight(), paint);
//canvas.drawColor(0xFFAAAAAA);
//canvas.drawBitmap(bm,0,0, paint);
}
(私はここにタッチメソッドを省略しています)!
@csm_dev isSimplePathと一致するコードはありません。私が上で提供したすべてのコードは、isSimplePathへの参照を持たないタッチメソッドを除いた私のViewクラス全体です。 – Raddish18