【问题标题】:unreachable statement on Android Studio?Android Studio 上无法访问的声明?
【发布时间】:2015-11-13 10:36:09
【问题描述】:

我在 Andoid 工作室得到了这个无法访问的声明,我尝试修复数据结构,但没有发生任何事情,有人可以帮助我吗?问题出在

this.income += ((Income) this.li.get(i)).getJumlah();

这是我的代码

public static int uang;
private Button btnDeveloper;
private Button btnExit;
private Button btnIncome;
private Button btnOutcome;
private Button btnPassword;
private Button btnReport;
private Dialog dialog;
private IncomeDataSource iDS;
private int income;
private Intent intent;
private ArrayList<Income> li = new ArrayList();
private ArrayList<Outcome> lo = new ArrayList();
private MoneyDataSource mDS;
private Money money;
private OutcomeDataSource oDS;
private int outcome;
private String tuang = "";
private TextView txtUang;


public void bindingList()
{
    this.li = getAllIncome();
    this.income = 0;
    int i = 0;
    if (i >= this.li.size())
    {
        this.lo = getAllOutcome();
        this.outcome = 0;
    }
    for (int j = 0; ; j++)
    {
        if (j >= this.lo.size())
        {
            return;
            this.income += ((Income) this.li.get(i)).getJumlah();
            i++;
            break;
        }
        this.outcome += ((Outcome)this.lo.get(j)).getJumlah();
    }
}

【问题讨论】:

  • 您在this.income += ((Income) this.li.get(i)).getJumlah(); 之前返回,因此无法访问。
  • return; 导致问题
  • 它正在输入'if'并返回。您的 for 循环或 if 条件存在问题
  • 返回的意义何在?你怎么没看到?
  • 哦,是的,我忘记了那些 :D 因为我太困了,谢谢它真的很有帮助

标签: android android-studio unreachable-statement


【解决方案1】:

只需从 if 循环中删除 return :)

public void bindingList()
{
    this.li = getAllIncome();
    this.income = 0;
    int i = 0;
    if (i >= this.li.size())
    {
        this.lo = getAllOutcome();
        this.outcome = 0;
    }
    for (int j = 0; ; j++)
    {
        if (j >= this.lo.size())
        {

            this.income += ((Income) this.li.get(i)).getJumlah();
            i++;
            break;
        }
        this.outcome += ((Outcome)this.lo.get(j)).getJumlah();
    }
}

【讨论】:

  • 但是当我尝试运行 java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
猜你喜欢
  • 2021-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-22
  • 2020-01-15
  • 2021-08-06
相关资源
最近更新 更多