| Author |
just another null pointer exception while working with array of objects
|
Vicky Chand
Greenhorn
Joined: Dec 10, 2008
Posts: 8
|
|
I am getting a null-pointer exception though i can't understand why can you guys help this is my main method
|
 |
Sunil Kumar
Ranch Hand
Joined: Apr 24, 2007
Posts: 76
|
|
What's the implementation of the constructor for Bank?? [ December 16, 2008: Message edited by: Sunil Kumar ]
|
Sunil Kumar
http://goodtoknowit.blogspot.com/
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
You're clearly intending this as the constructor of the Bank class: public void bank(){ but it's not, for two reasons. First, the name should be Bank, not bank; letter case matters. Second, constructors have no return types; if you write a method with the same name as the class, but use "void" as the return type, then it's a method, not a constructor. As a result of these issues, the code in this 'constructor' is actually never called. So this one line should be public Bank(){
|
[Jess in Action][AskingGoodQuestions]
|
 |
Sunil Kumar
Ranch Hand
Joined: Apr 24, 2007
Posts: 76
|
|
|
Agreed. Further adding a customer will throw ArrayIndexOutOfBoundsException
|
 |
Vicky Chand
Greenhorn
Joined: Dec 10, 2008
Posts: 8
|
|
Yeah!! right I am still new to the programming world so still making silly mistakes.
|
 |
Vicky Chand
Greenhorn
Joined: Dec 10, 2008
Posts: 8
|
|
one thing everyone missed out was that the bank array declaration was to be shifted in the second for loop Thank you all
|
 |
 |
|
|
subject: just another null pointer exception while working with array of objects
|
|
|