应用程序适用于调试步进,但不适用于正常调试或运行模式

时间:2017-01-28 10:43:20

标签: javascript java android

我最近遇到了一些问题,现在我设法让它在每次运行时都崩溃了。问题是,当我逐步调试应用程序时,但是当我取消步骤时,它每次都会崩溃......

这是代码:

String r = users.getListRatings();

    userHolder.tx_listratings.setText("     /     " + getAverage(r) + "     \uD83C\uDF1F"); //crashes here: at com.example.juanpablo.coffee.UserListAdapter.getView(UserListAdapter.java:86)


public int getAverage(String args) {
    String a = args;
    String[] x = a.split("");
    int add = 0;
    for (int i = 1; i < x.length; i++) {
        add = add + Integer.parseInt(x[i]); }
    int average = add / a.length(); //crashes here: at com.example.juanpablo.coffee.UserListAdapter.getAverage(UserListAdapter.java:114)
    return average;
}

这是崩溃:java.lang.ArithmeticException:除以零。

请帮助我,如果可以,如果downvote请解释原因,我是新的,需要改进。谢谢。

1 个答案:

答案 0 :(得分:0)

我通过将a.length()更改为i来修复此问题。

相关问题