Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nullpointer exception?

 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
System.out.println(al);

(above line prints null) for al.add(eb) it stucks? ?
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

You haven't initialised the ArrayList anywhere.

Sean
 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where it matters ?
doesn't it take the default value null?? As its instance variable??
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but you can't call methods on a variable that is null.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4015
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objects start as null until they are initialized. Since an ArrayList is an object, you must initialize it else its just a null pointer.
 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

thank you guys .

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

thank you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic