This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reg:java.lang.ArrayIndexOutOfBoundsException:  RSS feed

 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
when i execute the code below i get the error java.lang.ArrayIndexOutOfBoundsException: 2.

When i change the values in the for loop as
tabmat=temp1[0];
almat = temp1[1];
I get the correct out put but at last i get this error. Please suggest me.

java.lang.ArrayIndexOutOfBoundsException: 3



Thanks & Regards>
 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if j == temp1.length - 1?>
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Prime. For replying
If i do what you have said i just wont get any out put and no exception also.

Thanks & Regards
alexander
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Prime. For replying
If i do what you have said i just wont get any out put and no exception also.

Thanks & Regards
alexander
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I have got to know that the exception which i am getting is due to the i++. When i remove the increment operator i am not getting any exception but it is necessary to increment. So is there any other way.

Thanks and Regards
alexander
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Rob was not so much asking you for more information as trying to nudge you into discovering the problem for yourself. Remember that valid indexes for arrays are from 0 to array.length - 1. What indexes are you using? Particularly on the last iteration of the loop.
 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Charles wrote:I think Rob was not so much asking you for more information as trying to nudge you into discovering the problem for yourself. Remember that valid indexes for arrays are from 0 to array.length - 1. What indexes are you using? Particularly on the last iteration of the loop.

You're absolutely right
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!