File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes NullPointerException 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 » Java » Beginning Java
Bookmark "NullPointerException" Watch "NullPointerException" New topic
Author

NullPointerException

Joel Christophel
Ranch Hand

Joined: Apr 20, 2011
Posts: 231
    
    1





It compiles, but I get a NullPointerException, Why in the world is this happening?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37902
    
  22
Very common error. You create an array, which contains 300 nulls, until you assign something to them. Maybe you can iterate through the array and assign them all like this
myArray[i] = new Foo(...);


Remember: a newly-created array is implicitly full of nulls, until you put something in their place.
Claudiu Chelemen
Ranch Hand

Joined: Mar 25, 2011
Posts: 71

It's because you declared an array of elements, but no elements are inside it. Afterwards, you're trying to call the set methods on two objects that aren't there...

Claudiu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException
 
Similar Threads
"private" access
Interfaces and Filter Assignment
doesn't compile my code
Trouble calling this method
Calling a Method from another Class