java - Else can't find the If statement even though there is one -
when try compile code error saying else without if. believe have of braces in right place. other errors in picture have attached believe there because of can't use else without if error.
problem code:
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; } }
error:
if(maze[currcol + 1]currrow] == clear){
that's not valid; you're missing left bracket around currrow
in few places.
also, there's chunk of refactoring around this.