This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

NullPointerException  RSS feed

 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




It compiles, but I get a NullPointerException, Why in the world is this happening?
 
Campbell Ritchie
Sheriff
Posts: 55292
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
Eclipse IDE Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!