• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

just another null pointer exception while working with array of objects

 
Vicky Chand
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the implementation of the constructor for Bank??
[ December 16, 2008: Message edited by: Sunil Kumar ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(){
 
Sunil Kumar
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. Further adding a customer will throw ArrayIndexOutOfBoundsException
 
Vicky Chand
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah!! right
I am still new to the programming world so still making silly mistakes.
 
Vicky Chand
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one thing everyone missed out was that the bank array declaration was to be shifted in the second for loop
Thank you all
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic