簡體   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