aspose file tools*
The moose likes Beginning Java and the fly likes Why Null Pointer exception for this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why Null Pointer exception for this?" Watch "Why Null Pointer exception for this?" New topic
Author

Why Null Pointer exception for this?

Abhishek Mj
Greenhorn

Joined: Jan 07, 2013
Posts: 5
Why do I get null pointer exception for this code??

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

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?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Abhishek Mj
Greenhorn

Joined: Jan 07, 2013
Posts: 5
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 ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why Null Pointer exception for this?