This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Nullpointer exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
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: 3703

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

My Blog: Down Home Country Coding with Scott Selikoff
Jyoti Vaskar
Ranch Hand

Joined: Jun 30, 2009
Posts: 142

thank you guys .

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

thank you!
I agree. Here's the link:
subject: Nullpointer exception?
Similar Threads
Unable to find specific product
Problems when viewing specific description when search
File Operations Program Problem
insert statement is not working
Access database from a class file