public static void main(String [] args) throws IOException{
BufferedReader in = new BufferedReader(new FileReader(".../senses/command_list"));
String line = null;
while((line = in.readLine()) != null){
if(line.isEmpty()){
continue;
}
line = line.trim();
line = line.substring(2 + line.indexOf(">") , line.indexOf("))"));
System.out.println(line);
}
Following is an extract of the file
en_actions_.add(new ClusterEntry<String>("photography",-1, 2, 620554,"photography",null));
en_actions_.add(new ClusterEntry<String>("diagnostic procedure",-1, 1, 177127,"diagnostic procedure",null));
en_actions_.add(new ClusterEntry<String>("emergency procedure",-1, 1, 177783,"emergency procedure",null));
en_actions_.add(new ClusterEntry<String>("medical procedure",-1, 1, 1024392,"medical procedure",null));
en_actions_.add(new ClusterEntry<String>("process",-1, 5, 5470189,"process",null));
When I run this program, I encounter a String out of bounds exception with the following error message
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -2
and it points to the line with the indexOf operator.
Please let me know what I have done wrong.BTW the purpose, of the program is to store each field in an array of structures/classes. This is just the first part of the program.