Problem with StringTokenizer in android

Put your problem here if it does not fit any of the other categories.

Problem with StringTokenizer in android

Postby ravlawrance » Fri Dec 04, 2009 7:11 am

Hi friends,

Here is my coding,

if (localName.equals("description")) {
image_parser = builder.toString();

desc = Html.fromHtml(builder.toString().trim()).toString();

thumpImageUrl = image_parser;
int index = thumpImageUrl.indexOf ("<img");
String img = thumpImageUrl.substring (index + 4);
img = img.replace ("src=", "").trim ();
StringTokenizer tokenizer = new StringTokenizer(img,""");
String path = null;
while(tokenizer.hasMoreElements ())
{
path = tokenizer.nextToken ();
break;

}
thumpImageUrl = path;

rate = image_parser;
int index1 = rate.indexOf ("$");
String img1 = rate.substring (index1);

StringTokenizer tokenizer1 = new StringTokenizer(img1,"&");
String path1 = null;
while(tokenizer1.hasMoreElements ())
{
path1 = tokenizer1.nextToken ();
break;

}
rate = path1;

}


Im always getting the error that

12-04 11:34:03.260: WARN/System.err(814): java.lang.StringIndexOutOfBoundsException: String index out of range: -1


Please help me to solve the issue....
ravlawrance
Freshman
Freshman
 
Posts: 3
Joined: Wed Nov 25, 2009 8:36 am

Top

Postby ravlawrance » Fri Dec 04, 2009 8:08 am

Pleae help me to solve the issue friends. :)
ravlawrance
Freshman
Freshman
 
Posts: 3
Joined: Wed Nov 25, 2009 8:36 am

Postby hardcoras » Fri Dec 04, 2009 11:10 pm

Didn't take a lot of time to analyse your code, but i think the problem is:
String.indexOf() can return -1 if fragment not found. So before doing String.substring() you shoud check if your range falls inside your string.
hardcoras
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Sat Nov 14, 2009 2:31 pm
Location: Lithunia

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 12 guests