• Post Reply Bookmark Topic Watch Topic
  • New Topic

Another null pointer exception  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This program is for an exercise in a text book. It is supposed to create an array of random strings and sort them according to their HTML numbers. It creates the array correctly and even compiles correctly, but has a null pointer exception when it comes to the sorting. (I have cut out other parts of the program that were irrelevant).

the lines that produces the null Pointer Exception is line 24. if(array[i].charAt(0)>array[maxIndex].charAt(0))...and 53.stringSelectionSort(stringArray);

thank you.

 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your randomStringArray method, why are you not putting anything in the last element of your array ?
 
Eric Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANK YOU!

just changed line 65 to read


instead and it runs perfectly now, thank you!
 
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Mitchell wrote:THANK YOU!

just changed line 65 to read


instead and it runs perfectly now, thank you!

The standard way of doing this is:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!