• Post Reply Bookmark Topic Watch Topic
  • New Topic

Issues with OutOfBoundsException at 4  RSS feed

 
Sean Aitken
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi people I'm new to all this. At the moment I am studying it and the problem is Taking a range of names in an array and outputting them alphabetically, But for some reason I get an outOfBoundsException. And its starting to get to me.Umm Not 100% sure how to put the code in So aplogies in advance
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indexes in array's are zero based, so the last element in any given array would be (size - 1)... in your case (4 - 1) = 3... so the problem lies in your last access of names[4]= ("Anna");
 
Sean Aitken
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LOl thanks I didn't even see that Think I need to get outside and fresh air forawhile. I swear I have been looking at that for about an hour now doh! Thanks Rico
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Lots of people make that mistake; I have even seen it in a book.
 
Sean Aitken
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

Lots of people make that mistake; I have even seen it in a book.

Thanks Cambell, I am no longer amazed at what makes it through editing these days...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!