2015-09-27 56 views
-2

我想製作一個加密程序。語法錯誤,插入「最後」來完成BlockStatements不能修復

我該如何擺脫「語法錯誤,插入‘終於上線100

<imports> 

public class Afp { 

... 

/** 
* Initialize the contents of the frame. 
*/ 
private void initialize() { 
    .... 

    JButton btnEncrypt = new JButton("Encrypt"); 
    btnEncrypt.addActionListener(new ActionListener() { 
     public void actionPerformed(ActionEvent arg0) { 
      try{ 
       String text; 
       StringBuffer passWord = new StringBuffer(""+ text); 

      for(int i = 0; i < passWord.length(); i++){ 
       int temp = 0; 
       temp = (int)passWord.charAt(i); 
       temp = temp*9834/8942 /33 *90023243 * 9 +124324534 - 2335 *24324; 
       passWord.setCharAt(i, (char)temp); 
      } 
      } 


     } 
    }); 
    ... 
} 
} 
+3

'try'塊需要'catch'或/和'finally'。 –

+1

我刪除了第二個問題,將整個問題從「太寬」關閉。請將獨立(即不相關)的問題作爲不同的問題提出。 –

回答

4

你得到語法錯誤,因爲你已經寫try塊沒有catch或finally塊’來完成BlockStatements」。您可以刪除try塊或添加catch或finally

5

try聲明可能的語法去是這樣的:

// 1 try-catch 

    try { 
     .... 
    } catch (SomeException ex) { 
     ... 
    } 

// 2 try-catch-finally 

    try { 
     .... 
    } catch (SomeException ex) { 
     ... 
    } finally { 
     ... 
    } 

// 3 try-finally 

    try { 
     .... 
    } finally { 
     ... 
    } 

// 4 try with resources 

    try (...) { 
     ... 
    } 
    ... 

(在表格1,2和3,你必須至少有一個catchfinally ......或兩者兼而有之。在4年級,你可以離開了這兩個catchfinally塊,因爲有一個隱含的最終塊。)

您的代碼不符合任何這些。但是,對於您的代碼的正確修復取決於您試圖對try聲明執行的操作。如果您不知道,那麼也許只需刪除try {和匹配的}即可。

相關問題