嗯,我围绕我的返回语句在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()中出现异常,它会返回什么? –