是否可以檢查輸入字符串是否爲NumberFormatException
:""
?是否可以檢查java.lang.NumberFormatException?
我試着寫我的程序,這樣,如果用戶沒有把任何價值觀的錯誤信息會出來,而不是NumberFormatException異常的:
if(pasientNavnFelt.getText() == null || pasientNrFeIt.getText() == null)
{
utskriftsområde.setText("ERROR, insert values");
}
if(pasientNavnFelt.getText() != null || pasientNrFeIt.getText() != null)
{
// rest of code here if the program had values in it
}
:
if(pasientNavnFelt.getText() == "" || pasientNrFeIt.getText() == "")
{
utskriftsområde.setText("ERROR, insert values");
}
if(pasientNavnFelt.getText() != "" || pasientNrFeIt.getText() != "")
{
// rest of code here if the program had values in it
}
我也試過無效
我仍然得到:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
該程序工作正常,如果它有值。
當然,趕上例外。 –
合併一個try-catch塊來處理異常。 –