http://pastebin.com/m5fa7685e
It seems to fail when getting f3.. Output is:
not ready File is null Exception in thread "main" java.lang.NullPointerException at BuabFile.parseBUAB(BuabFile.java:93) at AddressBook.createBrowseForm(AddressBook.java:232) at AddressBook.(Addr开发者_Go百科essBook.java:51) at Main.main(Main.java:4)"
But not before then - no file not found errors or anything...
My guess would be that the parseBUAB() method receives a "null" argument. Which means that it could be that it is the AddressBook class is responsible for the error.
It looks like you forgot to assign a value to BuabFile.file
static field. You may want to add this to the end of your readFile()
method:
BuabFile.file = f3;
I am guessing your AddressBook.createBrowseForm
method looks something like this:
String filename = ...;
BuabFile buab = new BuabFile(filename);
buab.readFile();
ArrayList<String> buabLines = buab.returnFile(); // Returns null because readFile() never assigned a value to BuabFile.file
ArrayList<Buab> buabList = buab.parseBUAB(buabLines);
From all I can see, you just call parseBUAB(..)
with a null
value. I can't see the call to that method so you have to check the rest of your code.
For your 'not ready' output, which is created because your BufferedReader f3 is 'not ready', the API says
True if the next read() is guaranteed not to block for input, false otherwise.
Maybe you just call it too fast and the file is not loaded yet. Play with Thread.sleep() before calling ready() on the stream. Maybe a some-milliseconds blocking is just normal for File I/O.
And third - if f3
is the BufferedReader you want to keep, you have to assign it to the member file in the readFile()
method. But now that's all I found ;)
I'm confused further but have found an answer sort of - I'm using windows 7 and have tried it on a windows xp computer and the code compiles fine and reads in the file (other errors you lot have noted are to be changed anyway through development - this was just one stick in the way...).
I'm wondering if there is some Windows 7 error with eclipse and opening/reading files...
精彩评论