Hi, I am currently designing a program and I've run into a problem - It's probably really easy to solve, but heck it's late and I can't think lol.
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:
The activeCars variable comes from the method where the details are loaded from the text file - each time it loads a car, activeCars increments by 1.
But when I run this, I enter the new cars details, and I get a 'NullPointerExc eption' 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
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:
Code:
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 'NullPointerExc eption' 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
Comment