0

ユーザー入力フィールドを空白のままにして検索ボタンを押すと、次のエラーページが表示されます。

java.lang.NumberFormatException: For input string: ""
    java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    java.lang.Integer.parseInt(Integer.java:470)
    java.lang.Integer.parseInt(Integer.java:499)

エラーをスローするコードはint nstudentid = Integer.parseInt(studentid);

4

1 に答える 1

0

空の文字列から数値を解析しようとしています。チェックを追加する必要があります。

//this means the number is not empty
if(studentid != null && !studentid.equals("")){
    int studentIdNum = Integer.parseInt(studentid);
}
else{
   //no number, deal with it
   throw new Exception("Invalid student Id!");
}
于 2012-08-07T13:54:55.173 に答える