Java에서 TreeMap 구조를 사용하고 있습니다. 키에는 문자 ':'가 들어 있으며 값은 사물 목록입니다. 내가 프로그램이이 선에서 정지 디버깅 할 때 문제는 정말 문제가 될 수있는 아무 생각스캐너 hasNextLine()이 Java의 마지막 행에 액세스하지 않습니다.
if (!string.isEmpty()) {
**string = jin.nextLine();**
}
(더 이상 작동하지 ...)입니다. 아래는 내 코드입니다. 데이터 (내가 날짜 변수를 유지하는 곳)와 ListOfBills (Bill 클래스의 객체 목록을 유지하는 곳)는 두 개의 다른 클래스입니다. 이 입력을 기다리고 있기 때문에이 차단 계속
public void read(InputStream in) throws ParseException {
Scanner jin = new Scanner(in);
TreeMap<Date, ListOfBills> tree = new TreeMap<Date, ListOfBills>();
ListOfBills obBill = new ListOfBills();
Data data;
String string = jin.nextLine();
while (jin.hasNextLine()) {
if (string.contains(":")) {
data = new Data((string));
string = jin.nextLine();
while (!string.contains(":")) {
String[] parts1 = string.split(" ");
obBill.listOfBills.add(new Bill(Integer.parseInt(parts1[0]), Float.parseFloat(parts1[2]),
parts1[3], Float.parseFloat(parts1[5])));
if (!string.isEmpty()) {
string = jin.nextLine();
}
}
tree.put(data.date1, obBill);
}
}
for (Date date : tree.keySet()) {
System.out.println(date + "\n");
}
jin.close();
}
당신이 아닌 희망이 도움이 경우 표준 입력에 값을 입력해야 'string = jin.nextLine(); '을 호출 할 때마다'jin.hasNextLine()'을 테스트하면 오류가 발생하기 쉽습니다. –
'if (string.contains (":"))'가 거짓이면 무한 루프가됩니다. –