Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -60
I keep getting this error, and I've been try to figure it out, but I just can't! I'm just starting java so any and all help is much appreciated! Here's my code:
//This method takes large amounts of text and formats
//them nicely in equal lenth lines for the console.
public void print(String a){
String textLine = a;
int x = 60;
List<String> splitText = new ArrayList<String>();
//limits the amount of characters in a printed line to 60 + the next word.
while (textLine.length() > 60) {
if (textLine.substring(x+1,1) == " "){
splitText.add(textLine.substring(0,x+1));
textLine = textLine.substring(x+2);
x = 0;
}
else {
x++;
}
}
splitText.add(textLine);
for (int y = 0; splitText.size() < y;y++){
System.out.println(splitText.get(y));
}
}