添加“ drawPath myline”后,为什么我的apk在运行时崩溃了

时间:2020-07-24 13:28:46

标签: java android path

添加 mylines 后,此代码已编译为0个错误。但是,当我安装时,崩溃显示无法打开。

如果我删除了 mylines ,那么效果很好。 我不知道是什么问题?

canvas.drawPath(myLines,greenPaint);

package com.bennyplo.graphics2d;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.provider.DocumentsContract;
import android.view.View;

public class MyView extends View {
    private Paint redPaint;
    private Paint bluep;
    private Paint greenPaint;
    private  Path myLines;

    public MyView(Context context) {
        super(context, null);
        //Add your initialisation code here
        redPaint=new Paint(Paint.ANTI_ALIAS_FLAG);
        redPaint.setStyle(Paint.Style.STROKE);//stroke only no fill
        redPaint.setColor(0xffff0000);//color red
        redPaint.setStrokeWidth(5);//set the line stroke width to 5

        bluep = new Paint(Paint.ANTI_ALIAS_FLAG);
        bluep.setStyle(Paint.Style.STROKE);
        bluep.setColor(0xFF3353EC);
        bluep.setStrokeWidth(5);


        greenPaint = new Paint();
        greenPaint.setStyle(Paint.Style.STROKE);
        greenPaint.setARGB(255, 0, 255, 0);
        greenPaint.setStrokeWidth(5);//set the line stroke width to 5

        Path mylines = new Path();
        myLines.moveTo(0, 0);
        myLines.lineTo(1, 1);
        myLines.lineTo(2, 2);
        myLines.lineTo(3, 3);
        myLines.lineTo(4, 4);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //Add your drawing code here
        canvas.drawRect(500, 500, 700, 700 ,redPaint);
        canvas.drawCircle(600, 600, 145, bluep);
        canvas.drawPath(myLines, greenPaint);
    }
}

0 个答案:

没有答案
相关问题