当JTextfield为空时,如何打印"Error“
save.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
String sn =jX1.getText();
if (sn==null){
System.out.println("Error");
System.out.println("T");
}谢谢
发布于 2015-04-28 01:41:21
尝试使用故障保护方法。另外,在评论的基础上,您应该以更好的格式记录数据。Java托管了大量不同的方法来记录某些数据。look here
至于您的错误处理,请尝试-捕获-最终。这不是经过测试的代码。如果您遇到任何问题、try-catch文档和其他语句here或here,请让我知道
public static void main(String[] args) {
while (String sn == null)
try {
String sn = JX1.getText();
} catch (Exception ex) {
System.out.println("Exception thrown!");
} finally {
if (sn != null) {
System.out.println("Closing PrintWriter");
sn.close();
} else {
System.out.println("PrintWriter not open");
}
} https://stackoverflow.com/questions/29902241
复制相似问题