• Post Reply Bookmark Topic Watch Topic
  • New Topic

Program not working "NullPointerException"  RSS feed

 
Greenhorn
Posts: 24
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why i am getting NullPointerException here?
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the l1 field is not set for the second MyList instance. Because the value is not "Simple" it goes to the else block, and only sets the l2 field.

Also, you shouldn't use == to compare Strings, but the equals method instead.
 
MrKamal Joshi
Greenhorn
Posts: 24
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah got it.I was making silly mistake.Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!