Welcome to Dream.In.Code
Become a Java Expert!

Join 150,411 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 953 people online right now. Registration is fast and FREE... Join Now!




build error help

 
Reply to this topicStart new topic

build error help

Synth
16 Mar, 2008 - 09:42 PM
Post #1

New D.I.C Head
*

Joined: 29 Aug, 2007
Posts: 44


My Contributions
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
            }
        }
    }
}

User is offlineProfile CardPM
+Quote Post

MoobeH
RE: Build Error Help
17 Mar, 2008 - 04:30 AM
Post #2

New D.I.C Head
*

Joined: 22 Nov, 2007
Posts: 21


My Contributions
Hey dude, problem is your method declarations are not static. So your main method doesn't like them, two ways you can get around this.

1) Declare your methods as static, so for example:

CODE
public [u]static[/u] void mazIn() throws FileNotFoundException, IOException


this may affect your codes behaviour though, so you'll need to understand what and how static methods work

2) Leave your code as it is, only now create another class with your methods in it.

In your main method, create an object of that class, and then use the methods of the object to manipulate the variables...


Hope this help.

Good luck

This post has been edited by MoobeH: 17 Mar, 2008 - 04:31 AM
User is offlineProfile CardPM
+Quote Post

Synth
RE: Build Error Help
17 Mar, 2008 - 05:59 AM
Post #3

New D.I.C Head
*

Joined: 29 Aug, 2007
Posts: 44


My Contributions
thanks MoobeH, i created a new class like u suggested and my program runs great now smile.gif ty
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:39PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month