aspose file tools*
The moose likes Beginning Java and the fly likes just another null pointer exception while working with array of objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "just another null pointer exception while working with array of objects" Watch "just another null pointer exception while working with array of objects" New topic
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: 24187
    
  34

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: just another null pointer exception while working with array of objects