Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why Null Pointer exception for this?

 
Abhishek Mj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do I get null pointer exception for this code??

 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the answer to that is always because you have an object reference that doesn't point to anything.

In your case, what is the value of i when you get to line 5?
 
Abhishek Mj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. Got it.. thanks for pointing. So if we use wrapper class, there won't be initialization done like i = 0. And is initialized to 'null' as any other object . So it cannot be used in any expressions before initializing it ! correct ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic