嗯,我圍繞我的返回語句在try catch塊中,所以我可以確保輸入的文本是字符串,因爲該方法需要字符串返回,但是我仍然得到一個錯誤當它在那裏時它需要一個return語句!爲什麼它仍然提示我缺少返回語句
public String getBatchName(){
try {
return textField1.getText();
} catch(InputMismatchException i){
JOptionPane.showMessageDialog(
null, "You have entered illegal characters for the batch name!"
);
}
}
新代碼:
public static String getBatchName(){
try {
return textField1.getText();
} catch(InputMismatchException i){
JOptionPane.showMessageDialog(
null, "You have entered illegal characters for the batch name!", "Error", JOptionPane.ERROR_MESSAGE
);
}
return textField1.getText();
}
如果getText()中出現異常,它會返回什麼? –