繼編程之後,卡住了。我得到這堆棧跟蹤:InputMismatchException,programmingbydoing第17課
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at Doing.LessonSeventeen.main(LessonSeventeen.java:23)
也在第8行它說「資源泄漏」鍵盤從未關閉「。
package Doing;
import java.util.Scanner;
public class LessonSeventeen {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in); // <- line 8
String FirstName, LastName, LoginName;
int Grade, IDNum;
double GPA;
System.out.println("What is your first name?");
FirstName = keyboard.next();
System.out.println("What is your last name?");
LastName = keyboard.next();
System.out.println("What is your grade (as a number)");
Grade = keyboard.nextInt();
System.out.println("What is your login name?");
LoginName = keyboard.next();
System.out.println("What is your Student ID number?");
IDNum = keyboard.nextInt();
System.out.println("And finally, what is your GPA? (Up to 4.0");
GPA = keyboard.nextInt();
System.out.println("Your information:");
System.out.println("Login: " + LoginName);
System.out.println("ID: " + IDNum);
System.out.println("Name:" + LastName + ", " + FirstName);
System.out.println("GPA: " + GPA);
System.out.println("Grade: " + Grade);
}
}
_沒有錯誤_,那麼你發佈錯誤。您是否搜索了警告的確切消息?資源泄漏......永遠不會關閉。 –
**線程「主」**中的異常。這不是一個錯誤? – rpax
「_keyboard永遠不會關閉_」所以關閉它。你真的需要我們嗎? – csmckelvey