Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

setting values in array

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where do you call the method?
 
Ufo Humanoidi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic