繁体   English   中英

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

[英]App works on debug stepping but not on normal debug or run mode

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

这是代码:

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: 除以零。

如果可以,请帮助我,如果否决,请解释原因,我是新手,需要改进。 谢谢你。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM