eclipse中无法访问的代码 [英] Unreachable code in eclipse

查看:49
本文介绍了eclipse中无法访问的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是什么意思?

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Unreachable Code    
at mycode.sample.main(sample.java:24) 

我希望可以找到发生错误的行.我以为"24"是行,但是我的项目中只有23行代码.

I'm hoping I can find the line where the error occurred. I thought "24" is the line, but I only have 23 lines of code in my project.

这是项目代码

package mycode;
import java.io.*;

public class sample {
  int first;
  int second;

  public sample (int fir,int sec)
  {
    fir = first;
    sec = second;
  }

  public void add()
  {
    System.out.println(first+second);       
  }

  public static void main(String[] args) throws IOException
  {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int f = Integer.parseInt(reader.readLine());
    // int s =  Integer.parseInt(reader.r   eadLine());
    sample sample2 = new sample(f,100);
    sample2.add();
  } 
}   

我想了解此错误消息.预先感谢.

I would like to understand this error message. Thanks in advance.

推荐答案

第一条消息线程"main"中的异常java.lang.Error:未解决的编译问题:表示您的代码无法编译.您需要确定错误并进行修复.现代IDEEclipse,Netbeans等标记编译错误.他们可以帮助您快速识别来源.

The first message, Exception in thread "main" java.lang.Error: Unresolved compilation problem:means your code does not compile. You need to identify the error and fix it. Modern IDEs e.g. Eclipse, Netbeans, etc flag compile errors. They can help you to quickly identify the source.

第二个错误:

Unreachable Code
at mycode.sample.main(sample.java:24

意味着永远不会到达第24行的代码.

means that the code at line 24 will never be reached.

以下是无法访问代码的示例:

Here is an example of unreachable code:

public void doSomething() {
    if (true) {
        return;
    }
    // All code below here is considered unreachable code
    doSomething()
}

这篇关于eclipse中无法访问的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆