Ich bekomme eine StringIndexOutOfBoundsException
für die Zeile lesen (line.charAt(0) == 'I')
, wo es String index is out of range at 0
heißt.StringIndexOutOfBoundsException beim Auswerten der Dateieingabe?
Ich bin mir nicht sicher, was ich hier tun soll.
QueueLinkedList<Customer> eventqueue = new QueueLinkedList<Customer>();
QueueLinkedList<Customer> customerqueue = new QueueLinkedList<Customer>();
int numberserved = 0, totalidletime = 0, longestbreak = 0, idletime = 0, linelength = 0, longestline = 0;
try {
File file = new File("customersfile.txt");
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
//empty lines
while ((line = reader.readLine()) != "") {
//first line of file
while ((line = reader.readLine()) != "300") {
Customer newcust = new Customer();
if (line.charAt(0) == 'I') {
newcust.id = line.charAt(11);
}
else {
newcust.arrtime = line.substring(14);
newcust.setarrtimesecs(newcust.arrtime);
newcust.setleavingtime(newcust.arrtime);
}
eventqueue.enqueue(newcust);
}
}
}
}catch (IOException e) {
e.printStackTrace();
}
Warum verwenden Sie reader.readLine())! = Null warum nicht nur hasNextLine(), ich denke, Ihr Weg wird wirklich leere Zeilen halten –