やばい 2020-02-04 22:51 采纳率: 0%
浏览 1108
已采纳

萌新求助Android Studio工程编译没问题,运行app就闪退,求大佬看看是什么问题

Myview.java//就是给坐标在屏幕上画圆的代码,不知道哪里错了555555

public class MyView extends View {
    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    private int a;
    public MyView(Context context) {
        super(context);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        Paint paint = new Paint();
        zuobiao t = new zuobiao();
        t.getnumber(10, 0.5);
        t.amath();
        t.showmath();
        t.setax();

        for (int i = 0; i < t.a; i++) {
            for (int j = 0; j < t.a; j++) {
                canvas.drawCircle(Float.valueOf(t.x1.get(i).toString()), Float.valueOf(t.y1.get(j).toString()), 50, paint);
                paint.setStyle(Style.STROKE);
            }

        }
    }
}


zuobiao.java

public class zuobiao {
private double length,round;

public double result;
public   static double agle=(Math.asin(Math.sqrt(3)/3))-Math.PI/6;
double a;
public ArrayList x1=new ArrayList();
public ArrayList x2=new ArrayList();
public ArrayList y1=new ArrayList();
public ArrayList y2=new ArrayList();
public double c;
public void getnumber(double i,double j)
{this.length=i;
    this.round=j;
}


public void amath()
{c=(length-2*round)/(4*round*Math.cos(agle));
}
public double showmath()
{

    this.a=Math.floor(c);
    System.out.println(a);
    this.result=((length/4*round)*(2*a-1));
    return this.result;
}


public void setax()
{
    double[] x1 = new double [(int) this.a];
    double[] y1 = new double[(int) a];
    double[] x2 = new double[(int) a];
    double[] y2 = new double[(int) a];
    double magle=Math.PI/3+agle;
    double xieb=2*round/Math.sin(magle);

    x1[0]=0;
    x2[0]=2*round*Math.cos(magle)-(xieb-2*round)*Math.cos(magle);
    y1[0]=0;
    y2[0]=2*round-(xieb-2*round)*Math.sin(magle);

    for(int i=1;(i<a);i++)
    {
        x1[i] = x1[i-1]+(4*round*Math.cos(agle));
        y1[i] = y1[i-1]+2*round;
        x2[i] = x2[i-1]+(4*round*Math.cos(agle));
        y2[i] = y2[i-1]+2*round;

    }
    for(int j=1;(j<a);j++)
    {
        this.x1.add(x1[j]);
        this.x2.add(x1[j]);
        this.y1.add(x1[j]);
        this.y2.add(x1[j]);
    }

}

}

  • 写回答

1条回答 默认 最新

  • 代码的灵魂是bug! 2020-02-05 13:04
    关注

    报错信息帖出来看看,

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?