• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayIndex Out of bounds exception  RSS feed

 
Baskar Smuthu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I got an error an ArrayIndexoutofBoundsException in the following code. I know it will come when we cross the index level. But I checked in debug mode , value are passing clearly. Can anyone suggest me? Thanks in advance!

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see some of logical errors

1.
is it const.length() or tokens.length ? (not sure though...)

2. when you split a string with a particular identifier say =

then left side of the identifier goes at zero index of string array and right value goes to first index.

then why do you access 2nd index ?

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Baskar Smuthu

Please use code tag while posting your code. this time I have added them for you!
 
Baskar Smuthu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:Welcome to JavaRanch Baskar Smuthu
ok, got it.. Thank you so much... Now Onwards, I will post with code tag...
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Baskar Smuthu wrote:ok, got it.. Thank you so much... Now Onwards, I will post with code tag...

A few other things for you:

First
cont.split("&")
returns a String[], so
String []tokens=new String[120];
is redundant. Just do
String []tokens = cont.split("&");

Second
System.out.println(cont.length());
should have made it clear what your error was, because that will print out the number of characters in cont.
What (I assume) you want to do is to process all the tokens in tokens, so I would look at your for loop again.

Third
I'm not quite sure why you have the initial "&" in cont. All that will do is cause the first token to be empty.

Fourth
tokens[i].split("=")
should return an array of two items, so what will their indexes be?

HIH

Winston
 
Baskar Smuthu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
Baskar Smuthu wrote:ok, got it.. Thank you so much... Now Onwards, I will post with code tag...

A few other things for you:

First
cont.split("&")
returns a String[], so
String []tokens=new String[120];
is redundant. Just do
String []tokens = cont.split("&");

Second
System.out.println(cont.length());
should have made it clear what your error was, because that will print out the number of characters in cont.
What (I assume) you want to do is to process all the tokens in tokens, so I would look at your for loop again.

Third
I'm not quite sure why you have the initial "&" in cont. All that will do is cause the first token to be empty.

Fourth
tokens[i].split("=")
should return an array of two items, so what will their indexes be?

HIH

Winston



Thank you so much BOSS. I understood your answer clearly. Its helped me lot.. I have solved..Thanks....
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!