Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

setting values in array  RSS feed

 
Ufo Humanoidi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to use an array in my program but it always gives me NullPointerException. It think the exception refers that the array has only null values when I'm trying to give them a value. Take a closer look at the code:




And so on.

The exact message I get looks like this:
Exception in thread "main" java.lang.NullPointerException
at Anagrammi.tarkastaTarkasti(Anagrammi.java:34)
at Anagrammitestaaja.teeTestit(Anagrammitestaaja.java:48)
at Anagrammitestaaja.main(Anagrammitestaaja.java:24)


What's going wrong. I had the same problem with another program too, but I solved it by creating a constant sized array (in other words the array size was defined by a constant, not variable).
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where do you call the method?
 
Ufo Humanoidi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's in another class, witch has been already given. I don't have permission to make changes to that class.

Edit: And the upper code is not a complete program, there are more methods in overall.
[ March 07, 2006: Message edited by: Ufo Humanoidi ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This line is in your constructor. Because you redeclare the variable named testitaulukko in the constructor, it shadows the instance varaible. So the instance variable is still null.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!