2014-09-27 74 views
-2

我在我的程序中有一个错误: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(); 

}              
+1

使用您的IDE格式化工具缩进代码,您应该能够看到问题。 – Pshemo 2014-09-27 18:42:35

+0

[Error:'else'without'if']的可能重复(http://stackoverflow.com/questions/13059729/error-else-without-if) – 2014-10-15 02:29:26

回答

2

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

if (input.equals(cool));

删除;

1

移除多余的分号这里

if (input.equals(cool));