• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with Run time Errors

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everything Compiles, but will not run. Thanks for any advice.
It gives a Null Pointer Exception
Updated Code
now getting java.lang.ArrayIndexOutOfBoundsException: 0
on line 8
[Added code tags - see UseCodeTags for details]
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello and welcome to the Ranch!

Please UseCodeTags (<-click) and proper indentation when posting code. That way your code will be more readable and thus will increase chances of getting a good answer.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code.

When you say it doesn't run do you mean it doesn't give the output you expect, throws an exception or is it something else altogether, TellTheDetails.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As for your original question, the code you provided is throwing NullPointerException. The reason for such behavior is that seq array is not initialized. You probably tried to initialize it in your constructor with this line:

but what you did is you actually declared a variable with the same name local to the constructor, thus hiding your field which remains uninitialized.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also ItDoesntWorkIsUseless
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first piece of advice would be that you need to give us more information. When you say "will not run", does that mean there's no output, or there's an error? If there's an error, what is it?

If it's just a lack of output, the next step would be to work out what's going on. If you've got a debugger then use that to step through the program, otherwise just sprinkle System.out.println() statements liberally. You want to find out if the bits of code you expect to get run are actually getting run, and whether the variable values are what you expect.

However, now I've formatted the code I can see at least one problem. Line 9. There you are declaring a local variable seq, which hides the instance variable declared on line 4. That means your instance variable never gets initialised, so when you come to print things out there's nothing to print.

And welcome to the Ranch!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic