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

萌新求助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
    关注

    报错信息帖出来看看,

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

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名