File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Nullpointer exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Nullpointer exception?" Watch "Nullpointer exception?" New topic

Nullpointer exception?

Jyoti Vaskar
Ranch Hand

Joined: Jun 30, 2009
Posts: 142
Can anybody solve this problem???

I am trying to store the data from database(table jyoti) in a bean
& then adding the bean into an arraylist.

here is my code:

what's wrong with the above code?
I am getting Nullpointer exception?
it's stucking up after

(above line prints null) for al.add(eb) it stucks? ?

Sean Clark

Joined: Jul 15, 2009
Posts: 377


You haven't initialised the ArrayList anywhere.


I love this place!
Jyoti Vaskar
Ranch Hand

Joined: Jun 30, 2009
Posts: 142
where it matters ?
doesn't it take the default value null?? As its instance variable??
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Yes, but you can't call methods on a variable that is null.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3740

Objects start as null until they are initialized. Since an ArrayList is an object, you must initialize it else its just a null pointer.

[OCA 8 Book] [Blog]
Jyoti Vaskar
Ranch Hand

Joined: Jun 30, 2009
Posts: 142

thank you guys .

I got my problem & I'm sort with it.

thank you!
It is sorta covered in the JavaRanch Style Guide.
subject: Nullpointer exception?