2017-11-12 4 views
-2

도와주세요.보고되지 않은 IOException

Error unreported exception java.io.IOException; must be caught or declared to be thrown 

라인에서 나는를 만들 : 그것은 나에게 오류를 보여줍니다 그러나

try { 
    ObjectMapper mapper2 = new ObjectMapper(); 

    File file2 = new File("Lessons.json"); 

    List<Lesson> lessonList = Arrays.asList(mapper2.readValue(file2, Lesson[].class)); 
}catch (Exception e) { 
    e.printStackTrace(); 
} 

: 나는 JSON 파일에서 데이터를 읽고 자바 objects.Here에 저장하려고하면 코드 개체 목록입니다.

+5

게시 한 코드 블록이 해당 오류를 생성 할 수없는 것으로 보입니다. 질문을 편집하여 오류 및 정확한 오류를 생성하는 완전한 컴파일 가능한 코드 예제를 보여주십시오. – Kenster

+0

봄을 사용합니까? – Salman

+0

아니, 아니야 ... – user8928579

답변

0

나는 try-catch이 A 클래스 바로 아래 있다는 것을 알 수 있습니다. 어떤 방법이든지 안에 있는지 확인하십시오. 블록이 이미 존재하기 때문에 위의 오류가 표시되지 않아야합니다. catch (Exception e) 블록이 이미 있습니다. 아래 샘플 코드는 저에게 잘 작동합니다.

public static void main(String[] args) { 
    try { 
     ObjectMapper mapper2 = new ObjectMapper(); 
     File file2 = new File("Lessons.json"); 
     List<Lesson> lessonList = Arrays.asList(mapper2.readValue(file2, Lesson[].class)); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
}