2013-09-30 3 views
-1

다음은 무엇을 의미합니까?연결할 수없는 코드

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

오류가 발생한 행을 찾을 수 있기를 바랍니다. "24"가 줄줄 알았지 만 프로젝트에는 23 줄의 코드 만 있습니다.

다음은 프로젝트 코드 나는이 오류 메시지를 이해하고 싶은

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(); 
    } 
} 

입니다. 미리 감사드립니다.

+5

관리 코드를 공유 할 수 있습니다. –

+0

코드에 도달 할 수 없습니다. 즉, 무한 루프 이후에 진술을했을 것입니다. –

+0

@ JoshM. 꼭 그런 것은 아닙니다. 다른 상황도있을 수 있습니다. –

답변

4

첫 번째 메시지 인 Exception in thread "main" java.lang.Error: Unresolved compilation problem:은 코드가 컴파일되지 않는다는 것을 의미합니다. 오류를 식별하고 수정해야합니다. 현대 IDE 예 : Eclipse, Netbeans 등 플래그 컴파일 오류. 그들은 당신이 원천을 빨리 식별하도록 도울 수 있습니다.

두 번째 오류는 :

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

라인 (24)의 코드에 도달되지 않습니다 것을 의미합니다. 여기

는 도달 할 수없는 코드의 예입니다

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

하지만 프로젝트에는 23 줄 밖에 없습니다. – wormwood

+0

코드를 게시했습니다. – wormwood

4

은, 당신의 생성자를 변경해보십시오 :

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

에 :

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

예, 방금했습니다. "연결할 수없는 코드"가 사라졌습니다. 그러나 나머지는 여전히 거기에 있습니다. – wormwood

+0

나머지는 무엇입니까? 더 많은 오류가 있습니까? 나는 당신의 코드를 시험해 보았고 나에게 잘 돌아 간다. –

+0

Mor 에러가 아니라 "unrechable code goes away"라인 만있다. 이와 같이 : 스레드 "main"의 예외 java.lang.Error : 해결되지 않은 컴파일 문제 : \t at mycode.sample.main (sample.java:24) – wormwood

관련 문제