Exception in thread "main" java.lang.NullPointerException
at Library.loadBooks(Library.java:179)
at UseLibrary.main(UseLibrary.java:105)
这个错误让我抓狂!
public void loadBooks(String s) throws IOException{
String str[] = new String[6];
String inFName = ".//" + s ;
BufferedReader input = new BufferedReader(new FileReader(inFName));
int x;
double y;
String line = "";
while(line != null){
for(int i=0; i<6; i++){
str[i] = new String();
line = input.readLine();
str = line.split("[-]");
x = Integer.parseInt(str[1]);
y = Double.parseDouble(str[2]);
Book a = new Book(str[0], x, y, str[3], str[4], str[5]);
add(a);
}
}
}
这段代码有什么问题?
我初始化了数组,但它没有运行!
更新 1
在save.txt
我有
1 Don Knuth-290-23.45-The Art of Programming with Java-HG456-Engineering-5
2 A. Camp-400-13.45-An Open Life-HSA234-Philosophy-1
3 James Jones-140-12.11-Oh, Java Yeah!-SDF213-Science Fiction-2
4 J. Campbell-250-32.45-An Open Life-JH45-Science-3
5 Mary Kennedy-230-56.32-Intro to CS Using Java as the Language-USN123-Science-4