如果没有,则出错

时间:2014-09-27 18:39:27

标签: java if-statement

我的程序中出现错误:else without if但是,我认为我有一个非常好的ifelse。我认为问题是因为我有try/catches吨。我只有一个错误,就是这样。继承我的代码:

     BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader("pass.txt"));
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(rootPane,"Please run setup. Password file not found");
        Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
        try {
            StringBuilder sb = new StringBuilder();
            String line = null;
            try {
                line = br.readLine();
            } catch (IOException ex) {
                Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
            }

            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                try {
                    line = br.readLine();
                } catch (IOException ex) {
                    Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            String cool = sb.toString();
            char[] input = jPasswordField1.getPassword();
            if (input.equals(cool)); {
                JOptionPane.showMessageDialog(rootPane,"Password is correct!");

            } finally {
            try {
                br.close();
            } catch (IOException ex) {
                Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        }   catch (FileNotFoundException ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
             try {
                 br.close();
             } catch (IOException ex) {
                 Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
             }
    }
    char[] input = jPasswordField1.getPassword();

}                                                      

2 个答案:

答案 0 :(得分:3)

我在您发布的代码中没有看到任何else(也许您遗漏了一些代码),但错误可能在这里:

if (input.equals(cool));

删除;

答案 1 :(得分:2)

在此处删除额外的分号

if (input.equals(cool));