2013-04-25 66 views
0

當我嘗試編譯此代碼時,我得到一個錯誤,說如果沒有if。我相信我擁有正確的地方所有的大括號。我還得到了其他的錯誤信息,但我只相信他們在那裏,因爲如果錯誤不能使用其他錯誤。其他人無法找到If語句,即使有一個

問題代碼:

public static boolean goNorth(){ 
     boolean success; 
     if(maze[currCol]currRow - 1] == CLEAR){ 
      maze[currCol][startRow -1] = PATH; 
      currRow--; 
      success = goNorth(); 
       if(!success){ 
       success = goWest(); 
        if(!success){ 
        success = goEast(); 
         if(!success){ 
          maze[currCol][currRow] = VISITED; 
          currRow++; 
          } 
         } 
        } 
        return success; 
       } else { 
        return false; 
      } 
     } 

    public static boolean goWest(){ 
     boolean success; 
     if(maze[currCol - 1]currRow] == CLEAR){ 
      maze[currCol - 1][startRow] = PATH; 
      currRow--; 
      success = goWest(); 
       if(!success){ 
       success = goSouth(); 
        if(!success){ 
        success = goNorth(); 
         if(!success){ 
          maze[currCol][currRow] = VISITED; 
          currCol++; 
          } 
         } 
        } 
        return success; 
       } else { 
        return false; 
      } 
     } 

     public static boolean goEast(){ 
     boolean success; 
     if(maze[currCol + 1]currRow] == CLEAR){ 
      maze[currCol + 1][startRow] = PATH; 
      currRow--; 
      success = goEast(); 
       if(!success){ 
       success = goNorth(); 
        if(!success){ 
        success = goSouth(); 
         if(!success){ 
          maze[currCol][currRow] = VISITED; 
          currCol--; 
          } 
         } 
        } 
        return success; 
       } else { 
        return false; 
      } 
     } 

     public static boolean goSouth(){ 
     boolean success; 
     if(maze[currCol]currRow + 1] == CLEAR){ 
      maze[currCol][startRow + 1] = PATH; 
      currRow--; 
      success = goSouth(); 
       if(!success){ 
       success = goEast(); 
        if(!success){ 
        success = goWest(); 
         if(!success){ 
          maze[currCol][currRow] = VISITED; 
          currRow--; 
          } 
         } 
        } 
        return success; 
       } else { 
        return false; 
      } 
     } 

錯誤:

screen shot

+0

發佈錯誤文本,而不是鏈接到圖像。 – 2013-04-25 13:49:47

+0

如何使用任何IDE? – Vitaly 2013-04-25 13:50:54

回答

3
if(maze[currCol + 1]currRow] == CLEAR){ 

這不是有效的;你在幾個地方錯過了左邊的支架currRow

此外,還有一大塊的重構。

+1

你會做一個很好的語法分析器。 :) – 2013-04-25 13:48:18

+0

+1用於hawkeyeing它。當代碼太臃腫時,會發生這種情況 – 2013-04-25 13:50:47

+0

謝謝。您的幫助。我應該抓住這個。 – Jaylon253 2013-04-25 14:01:07

2

首先閱讀錯誤。在第一個錯誤之後,不要再讀取任何錯誤,直到您理解第一個錯誤。

的第一個錯誤是告訴你,你在這一行有一個語法錯誤:

if(maze[currCol]currRow - 1] == CLEAR){ 

(你再複製粘貼四次)。在currRow之前缺少[

+0

好的,謝謝你的幫助,我一定會在將來做到這一點。 – Jaylon253 2013-04-25 14:01:45