Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException

 
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
Pie
Posts: 48953
60
  • 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