我的程序中出现错误:else without if
但是,我认为我有一个非常好的if
和else
。我认为问题是因为我有大量的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();
}
最佳答案
我在您发布的代码中看不到任何else
(也许您遗漏了一些代码),但是错误可能在这里:if (input.equals(cool));
删除;
关于java - 错误否则没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26077902/