Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
If statement 为SQL安全设置空值时出现打印错误_If Statement_Jtextfield - Fatal编程技术网

If statement 为SQL安全设置空值时出现打印错误

If statement 为SQL安全设置空值时出现打印错误,if-statement,jtextfield,If Statement,Jtextfield,JTextfield为空时,如何打印“Error” save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String sn =jX1.getText(); if (sn==null){ System.out.println("Error"); System.out.prin

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");
        }

谢谢

尝试使用故障保护方法。同时在注释上扩展,您应该以更好的格式记录数据。Java拥有大量不同的方法来记录某些数据

至于错误处理,请尝试最终捕获。这不是经过测试的代码。如果您遇到任何问题、关于try-catch的文档和其他语句或


System.out
将写入终端。如果你想给终端写信,我想你会这么做,但你没有明确说明你是否想这么做。
    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");
    } 
}