자바 Exception in thread "main" java.lang.NullPointerException 도...
-
게시물 수정 , 삭제는 로그인 필요
자바 poem.txt에 있는 단어를 가나다 순으로 정렬하려고 하는데
Exception in thread "main" java.lang.NullPointerException
이렇게 나오네요 ㅠㅠ
어디가 잘못된건지 좀 도와주세요
import java.io.*;import java.util.Arrays;
import java.util.StringTokenizer;
class test {
@SuppressWarnings("null")
public static void main(String args[]) {
FileReader reader = null;
BufferedReader bufreader = null;
StringTokenizer str = null;
try {
reader = new FileReader("poem.txt");
bufreader=new BufferedReader(reader);
str=new StringTokenizer(bufreader.readLine());
int index = 0;
String[] arr = null;
while (str.hasMoreTokens()) {
arr[index] = str.nextToken();
index++;
}
Arrays.sort(arr);
for (String s : arr) {
System.out.print(s);
}
}
catch (FileNotFoundException fnfe) {
System.out.println("파일이 존재하지 않습니다.");
}
catch (IOException ioe) {
System.out.println("파일을 읽을 수 없습니다.");
}
finally {
try {
reader.close();
}
catch (Exception e) {
}
}
}
}
#자바 exception #자바 exception 종류 #자바 exception 만들기 #자바 exception in thread main #자바 exception e #자바 exception handling #자바 exception 클래스 #자바 exception throw #자바 exception in thread main java.lang.error unresolved compilation problem #자바 exception in thread main java.util.nosuchelementexception