There is nothing in that part of the code that I can see that would throw a StringIndexOutOfBoundsException. Possibly one of those methods that is being called, calls a String method that may throw it but this is just a guess since we can't see the rest of the code. If you want further help, post the FULL stack trace for the exception and post the full source code for the class.
As for the line that you are unsure about, the for loop statement has 3 parts, initialization, loop condition and loop action. So you can actually break this out into a while loop and it may be easier to understand...
int i = inputStream.read(data);while ((!cancelTransfer) & (i>-1)) { // The body of the loop goes here // ..... i=inputStream.read(data);}
(Note: that in that line of code, you probably really should have && instead of the & in the loop condition)
A wordy description of what that loop is doing then, is it starts of by attempting to read data from the inputStream, while it successfully reads data and that the transfer has not been cancelled, continue to process the data. After processing the data, attempt to read some more data and loop.
Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.
now I m almost sure that the exception happens from time to time when I execute the following code :
i=inputStream.read(data) in line 278
this code was originally written for Android and now I ported it to J2ME.
So if I keep reading the data and then from time to time I got the following exception
The message is java.lang.StringIndexOutOfBoundsException: Index -8 >= 16 ( the index is negative but not usually -8 can be -
Not the solution you were looking for?
IT issues often require a personalized solution. With Ask the Experts™, submit your questions to our certified professionals and receive unlimited, customized solutions that work for you.
Premium Content
You need an Expert Office subscription to comment.Start Free Trial