hi im making a maze programming and i got it to almost work but when i call my methods in my main is comes up with the errors
CODE
G:\AP Java\mazbuf\mazbuf.java:18: non-static method mazIn() cannot be referenced from a static context
mazIn();
^
G:\AP Java\mazbuf\mazbuf.java:19: non-static method mazSolve() cannot be referenced from a static context
mazSolve();
^
G:\AP Java\mazbuf\mazbuf.java:20: non-static method mazPrint() cannot be referenced from a static context
mazPrint();
im not sure y this occurs
this is my code, thanks for any help!
CODE
import java.io.*;
import java.util.*;
public class mazbuf
{
public String[][] maze = new String[18][20];//maze array
private int r = 0, c = 0, s = -1, begRow = 0, begCol = 0;//variables for array locations
private boolean mazSolve = false, solution = false;
public static void main(String[] args) throws IOException
{
mazIn();
mazSolve();
mazPrint();
}
public void mazIn() throws FileNotFoundException, IOException//changes the maze into an Array
{
BufferedReader kb = new BufferedReader(new FileReader("in_maze.txt"));//buffered reader is set to scan input file
String tempLine = "";
String tempCh = "";
for(int b = 0; b <= 17; b++)
{
for(int a = 0; a <= 19; a++)
{
tempCh = tempLine.substring(a, (a+1));
if(tempCh.equals("b"))//checks for the begining of the maze and sets the location if it is true
{
r = b;
c = a;
}
maze[b][a] = tempCh;//adds variable to maze array
}
}
}
public boolean mazSolve()//solves the maze
{
if((maze[r][s++] != "@") || (maze[r][s++] != "b") || (maze[r][s++] != "*") || (maze[r][s++] != "?") || (maze[r][s++] != "s"))
{
s = s++;
maze[r][s] = "@";
mazSolve();
}
else if((maze[r][s--] != "@") || (maze[r][s--] != "b") || (maze[r][s--] != "*") || (maze[r][s--] != "?") || (maze[r][s--] != "s"))
{
s = s--;
maze[r][s] = "@";
mazSolve();
}
else if((maze[r--][s] != "@") || (maze[r--][s] != "b") || (maze[r--][s] != "*") || (maze[r--][s] != "?") || (maze[r--][s] != "s"))
{
r = r--;
maze[r][s] = "@";
mazSolve();
}
else if((maze[r++][s] != "@") || (maze[r++][s] != "b") || (maze[r++][s] != "*") || (maze[r++][s] != "?") || (maze[r++][s] != "s"))
{
r = r++;
maze[r][s] = "@";
mazSolve();
}
else if(maze[r][s] == "s")
return true;
else if(s == -1)
{
maze[r][s] = "?";
s = 0;
}
else if(s == 0)
{
s = -1;
if(maze[r][s++] == "@")
{
s = s++;
mazSolve();
}
else if(maze[r][s--] == "@")
{
s = s--;
mazSolve();
}
else if(maze[r--][s] == "@")
{
r = r--;
mazSolve();
}
else if(maze[r++][s] == "@")
{
r = r++;
mazSolve();
}
}
return false;
}
public void mazPrint()throws FileNotFoundException, IOException//prints array
{
FileOutputStream out = new FileOutputStream("out_maze.txt");//outputstream is created for the file and to print to the text file
PrintStream p = new PrintStream(out);
for(int b = 0; b <= 17; b++)
{
if(b != 0)//checks if its the very first input
p.println("");//line is read
for(int a = 0; a <= 19; a++)
{
p.print(maze[b][a]);//prints the array
}
}
}
}