i'm working on a program for my class but now i have a problem with spliting string and substrings. I have saved data from different classes in a string with a delimiter for later a later split(/). This part works fine and i get all the strings as i should saved in a new String array.
Later i tried to toast them in a for loop (String word: String array) and everything seemed fine. But i have a problem with cutting the substring from word. I would like to get the number (between '-' and 'k') but it always throws a String out of index error and i don't know why. When i tried to toast the position of the strings where i would like to take the substring, it shows them fine but when i try to substring with them it throws an error again.
The Error
"java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.uiuracun/com.example.uiuracun.Bill}: java.lang.StringIndexOutOfBoundsException: length=29; regionStart=22; regionLength=-18"
The Code
package com.example.uiuracun;
import android.R.anim;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class Bill extends ListActivity {
// Removed extra code
private void split(String[] string) {
for (String word:string){
word.trim();
int start = 0;
int end = 0;
start = word.indexOf('-');
end = word.indexOf('k');
String c = word.substring(start, end);
}
}
}
-kyou can make a SSCCE you post code that is not necessary, your problem it seems to be in your methodsplit,much noise there.