我得到在編譯時出現以下錯誤:我要趕InputMismatchException時,但它顯示編譯時錯誤
filimon.java:12: error: cannot find symbol
}catch(InputMismatchException ime){
^
symbol: class InputMismatchException
location: class filimon
1 error
我的源代碼是:
class filimon{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
try{
System.out.println("enter 2 integer values");
int a=s.nextInt();
int b=s.nextInt();
System.out.println("value of a: "+a);
System.out.println("value of b: "+b);
}catch(InputMismatchException ime){
System.err.println("please enter only number value");
}
catch(Exception e){
System.err.println(e);
}
}//main
}//filimon
問題是什麼?請幫幫我。
什麼是您的進口? –
毫無疑問,您還沒有確定編譯器包含哪些「InputMismatchException」類型。另外,你不處理這個異常,'catch(Exception e)'是一個反模式。請按照命名約定。 –