Reputation: 1
Hi i'm trying to use "ten dashes" between lines and i want to write it to an output file.i used writeFile method and the object oDel: oDel.writeFile("----------");
when i write this line eclipse gives me a null pointer execption.what can i do ? thanks for help.
public BankSystem(String dataFileName) {
this.iDel = new InputDelegate(dataFileName);
}
public BankSystem(String inputFileName, String outputFileName, ArrayList personList, ArrayList bankList, ArrayList branchList) {
this.iDel = new InputDelegate(inputFileName);
this.oDel = new OutputDelegate(outputFileName);
this.personList = personList;
this.bankList = bankList;
this.branchList = branchList;
Upvotes: 0
Views: 508
Reputation: 6342
So it seems like you're instantiating oDel in one of your constructors, but not the other (the one that only instantiates iDel). So, what if you were to instantiate a BankSystem object with the constructor that only instantiates iDel, but not oDel, and then try to use a method that writes the ten dashes with oDel? This would obviously create a NullPointerException to be thrown. So you will need oDel to be instantiated in both constructors if you are to implement a method that uses iDel. This is the best advice I can give based off your code. It might be more useful if you provide the code in full. However, I'm pretty confident this is why you're getting the error. What you could do is make a child class that "extends" the BankSystem class so that it incorporates the oDel object and its respective methods. If you're confused on this, let me know.
Upvotes: 1
Reputation: 5797
have you instantiated oDel?? (for example, oDel = new FileWriter(..)
)??
Upvotes: 2