简体   繁体   English

为什么Eclipse在返回后总是给我一个错误;

[英]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下方的代码(意味着您可以在elseif和after代码中返回return)是不可用的,因此会出现编译错误。

简单的答案,您不能在“ return”语句之后执行任何操作。

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

相关问题 为什么eclipse会让我的return语句出错? - Why does eclipse give me an error with my return statement? 为什么maven给我的不同的utf-8字符比eclipse(在eclipse中测试运行,在maven中失败)? - Why does maven give me different utf-8 characters than eclipse (test run in eclipse, fail in maven)? 为什么它给我 BufferUnderflowException - Why does it give me BufferUnderflowException 为什么声明一个新对象会给我一个语法错误? - Why does declaring a new object give me a syntax error? 为什么 heroku 会给我这个“不兼容的类型”错误? - Why does heroku give me this "incompatible type" error? 为什么 IntelliJ 会给我“包不存在”错误? - Why does IntelliJ give me "Package doesn't exist" error? 为什么这个while循环给我一个语法错误? - Why does this while loop give me a syntax error? 为什么“即时”转换在Java中给我一个编译错误? - Why does “on-the-fly” casting give me a compile error in Java? 为什么我的ButtonGroup给了我一个“ <identifier> 预计“错误? - Why does my ButtonGroup give me an “<identifier> expected” error? 为什么即使我声明了 rand,它也会给我一个错误? - Why does it give me an error even though I declared rand?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM