• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Null pointer exception trouble

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on a program that will grade tests and return the test scores, the average, highest, and lowest scores, and will sort the scores from highest to lowest. The program allows the user to input answers for only one of the students, the rest of the student answers are hard-coded. I am having trouble with a null pointer exception on the line that says:

char studAns[][] = new char[][]

I am also unsure about the sorting method that I used, I have been having problems trying to find a simple sorting algorithm that will allow the data in the array to maintain it's same index number while being sorted.

here is the code



[ May 17, 2006: Message edited by: Jason Rod ]

[ May 17, 2006: Message edited by: Jason Rod ]

[ May 17, 2006: Message edited by: Jason Rod ]
[ May 17, 2006: Message edited by: Jason Rod ]
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember that an array reference is null until you instantiate it.
[ May 17, 2006: Message edited by: Keith Lynn ]
 
Jason Rod
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I'm new to using arrays, how would I instantiate it in this case?
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jason Rod : Sorry, I'm new to using arrays, how would I instantiate it in this case?

Something like this:


Also remember that arrays in Java are 0 based, so an array with length = 10 will have indices 0 - 9.
 
Jason Rod
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh ok, got it, thanks so much
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please dont forget to post the entery point and order of the calls, next time. The program behavior depends on the order of the method calls.

Thank you.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic