• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayIndexOutOfBounds  RSS feed

 
Rrohit rakesh upadhyay
Ranch Hand
Posts: 94
1
Java Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote the following code to implement merge sort



But it is giving me the following exception



I do not know why i am getting this and how to fix this.Can someone please help.
 
Liutauras Vilda
Sheriff
Posts: 4927
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rrohit,

Lets assume you have an array:

You're getting ArrayIndexOutOfBoundsException when you're trying to access position within an array, which doesn't exist.
Example:

Start debugging by trying put the print statements before the line, where exception is being thrown.
Example:
 
Jay Tee
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would investigate this portion of your code:


 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Good catch.
 
Rrohit rakesh upadhyay
Ranch Hand
Posts: 94
1
Java Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jay Tee, that fixed my code. Thanks for your advice Liutauras Vilda
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!