[英]Why does Eclipse always give me an error after return;
I have some problem with eclipse android. 我对Eclipse Android有一些问题。
I have some java files, but if I call a method after return; 我有一些Java文件,但是如果我在返回后调用方法; (see the example) it tells me to remove the method. (请参见示例),它告诉我删除该方法。 Why? 为什么? I'm using Android 1.6. 我正在使用Android 1.6。
public void onClick(View paramView)
{
switch (paramView.getId())
{
default:
case 2131296257:
}
while (true)
{
return;
fetchAlarmSettings(); <-- It tells me to remove this.
if (this.strAlarmOnOff.equals("0"))
{
this.butAlarmSet.setText("Turn Alarm Off");
this.db.updateSetting("alarmTime", this.strHour.concat(this.strMinute));
this.db.updateSetting("alarmOnOff", "1");
switch (this.cal.compareTo(Calendar.getInstance()))
{
default:
case -1:
}
while (true)
{
this.setNotifications.setAlarm(this.cal);
break;
this.cal.roll(5, 1);
}
}
this.butAlarmSet.setText("Turn Alarm On");
this.db.updateSetting("alarmOnOff", "0");
this.setNotifications.turnAlarmOff();
}
}
Thanks! 谢谢!
Your method will stop running the moment that the return
statement is hit. 一旦return
语句,您的方法将停止运行。 Basically it should give you an ' Unreachable code!
基本上,它应该为您提供“ Unreachable code!
' warning, since any code after the return statement will never be executed. '警告,因为return语句之后的任何代码都将永远不会执行。 Removing the return
keyword should fix the problem. 删除return
关键字应该可以解决此问题。
So basically Eclipse is telling you to remove the next line after the return
since it will never be executed. 因此,基本上,Eclipse告诉您在return
后删除下一行,因为它将永远不会执行。 If you remove the method call it will complain over what ever line you throw in next. 如果删除该方法调用,它将抱怨您接下来要插入的行。
Besides that, there are other (according to me) flaws with your code... having a while(true)
loop without a break condition in this case seems odd (but then again I might be wrong here). 除此之外,您的代码还有其他缺陷(根据我)...在这种情况下,有一个while(true)
循环而没有中断条件的情况似乎很奇怪(但是我在这里可能还是错了)。 Also, the default
block is usually found at the end of a series of case
statements. 同样, default
块通常位于一系列case
语句的末尾。 Your second while(true)
loop will only iterate once since once the this.setNotifications.setAlarm(this.cal);
自从this.setNotifications.setAlarm(this.cal);
您的第二个while(true)
循环将仅迭代一次this.setNotifications.setAlarm(this.cal);
is executed the loop will stop iterating due to the break
statement. 被执行后,由于break
语句,循环将停止迭代。
Eclipse will not allow you to write obsolute code, actually the IDE uses java compiler for that. Eclipse不允许您编写绝对代码,实际上IDE为此使用Java编译器。
In this case the code below the return in certain branch (meaning that you can have return in the if
and after it code for the else
) is not reachable and thus you get compile error. 在这种情况下,某些分支中return下方的代码(意味着您可以在else
的if
和after代码中返回return)是不可用的,因此会出现编译错误。
简单的答案,您不能在“ return”语句之后执行任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.