Tuesday, December 20, 2011

What's wrong with my Android Java for loop?

I've been experimenting with Android Java using Eclipse and the Android SDK. I have written a for loop, the structure of which is as follows:





String arrString[] = myString.split(",");


int endstring = arrString.length;





for (int i=6; i%26lt;endstring; i+=6)


{


//do some stuff


}





the value in the variable 'endstring' is 290, as in the string array called arrString contains 290 separate strings.





When I run the program on the emulator, it crashes, but if I manually enter a value for 'endstring', up to at least 250 (as in 'int endstring = 250;'), it runs fine, and if I manually enter 290, it still crashes. Is there a limit for the max number of iterations of a for loop in Android Java? Anyone have any ideas how I can fix this problem?





Thanks.|||Are you sure it's crashing on the loop counter and not on code inside the loop that chokes after x number of iterations? It might help to know what error it's throwing when it crashes.



Nothing leaps out at me. It would help if you could also paste the error you're getting when it crashes on you. It should be in there somewhere. If you're using Eclipse, it should be in the logs.

No comments:

Post a Comment