Here is input I am supposed to parse: #typ offer; #det free essential supplies 4 evacs pets.; #loc 2323 55th st, boulder; #lat 40.022;
This is my code: System.out.print("Enter a tweet in the correct format: "); String tweet = keyboard.nextLine();
int start = tweet.indexOf("#");
int finish = tweet.indexOf(";");
String type = tweet.substring(start, finish);
String type2 = type.substring(4,finish);
String type_2 = type2.toUpperCase();
String tweet2 = tweet.substring(finish + 1);
int start2 = tweet2.indexOf("#");
int finish2 = tweet2.indexOf(";");
String detail = tweet2.substring(start2, finish2);
String detail2 = tweet2.substring(5, finish2);
String tweet3 = tweet2.substring(finish2 + 1);
int start3 = tweet3.indexOf("#");
int finish3 = tweet3.indexOf(";");
String location = tweet3.substring(start3 , finish3);
String location2 = tweet3.substring(4, finish3);
/*
String tweet4 = tweet3.substring(finish3 + 1);
int start4 = tweet4.indexOf("#");
int finish4 = tweet4.indexOf(";");
String latitude = tweet4.substring(start4, finish4);
String latitude2 = tweet4.substring(4, finish4);
String tweet5 = tweet4.substring(finish4 + 1);
int start5 = tweet5.indexOf("#");
int finish5 = tweet5.indexOf(";");
String longitude = tweet5.substring(start5, finish5);
String longitude2 = tweet5.substring(4, finish5);
*/
System.out.println();
System.out.println("Type: " + type_2);
System.out.println("Detail: " + detail2);
System.out.println("Location: " + location2);
//System.out.println("Latitude: " + latitude2);
//System.out.println("Longitude: " + longitude2);
keyboard.close();
Ignoring the commented part this line, String location = tweet3.substring(start3 , finish3);, is giving me this error, 40.022;Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -2 at java.lang.String.substring(Unknown Source) at ParseTheTweet.main(ParseTheTweet.java:31).
I commented out other parts to test my code on the given input and it works up until that point. Any ideas on why this is the case?