I'm designing a program to store details of cars (i.e. a garage), and the car details are all stored in a text file, and the text file is terminated with ****. The program first loads the existing car details using a BufferedReader, then each cars details is converted into a position in the carDetails object. The user can then perform manipulation to the data, delete a car, add a new car etc. Then when a manipulation is complete, the data is written back to the text file using a PrintWriter.
I'm currently trying to add a new car, and I have this code to do so:
Expand|Select|Wrap|Line Numbers
- tempRegNo = Text.readString("Please enter the new cars registration number.");
- tempManufacturer = Text.readString("Please enter the manufacturer");
- tempModel = Text.readString("Please enter the model");
- tempYear = Text.readInt("Please enter the year");
- tempPrice = Text.readInt("Please enter the price");
- carDetails[activeCars].setRegNo(tempRegNo);
- carDetails[activeCars].setManufacturer(tempManufacturer);
- carDetails[activeCars].setModel(tempModel);
- carDetails[activeCars].setYear(tempYear);
- carDetails[activeCars].setPrice(tempPrice);
- activeCars++;
But when I run this, I enter the new cars details, and I get a 'NullPointerException' error. I'm assuming it's looking in the wrong position or something, but I honestly can't figure it out at the moment...just wondering if anyone can offer any pointers?
Hopefully that doesn't sound too confusing :p
Thanks