Results 1 to 4 of 4
  1. #1
    warp is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Non static method printBoard(boolean) cannot be referenced from a static context

    Java Code:
    public class StrategoEngine
    {
       public StrategoEngine(boolean showBothPlayers){
         if (showBothPlayers==true)
                  [I]StrategoBoard.printBoard(true);[/I] //this is the line,where the error comes up
                StrategoBoard.printBoard(false);}
                
                public StrategoEngine(){}
                
                public static void printNotation(){
            System.out.println("Red Pieces are denoted with Upper case letters.");
            System.out.println("Blue Pieces are denoted with lower case letters.");
            System.out.println("SPY/spy: Kataskopos/Spy");
            System.out.println("DET/det: Anixneutis/Detector");
            System.out.println("SAB/sab: Saboter/Saboteur");
            System.out.println("SER/ser: Loxias/Sergeant");
            System.out.println("LIE/lie: Ypoloxagos/Lieutenant");
            System.out.println("CAP/cap: Loxagos/Captain");
            System.out.println("MAJ/maj: Tagmatarxis/Major");
            System.out.println("COL/col: Syntagmatarxis/Colonel");
            System.out.println("GEN/gen: Stratigos/General");
            System.out.println("MAR/mar: Stratarxis/Marshal");
            System.out.println("FLA/fla: Shmaia/Flag");
            System.out.println("BOM/bom: Vomva/Bomb");
            
            }
            public void nextMove(char xOrig, int yOrig,char xDest, int yDest){
            }
                
        }

    From another class, the StrategoBoard, I used the method PrintBoard
    Java Code:
     public void printBoard(boolean printSolution){
            
            if(printSolution==true){
            System.out.println("10 "+p[0][0].getType()+ "   "+p[0][1].getType()+p[0][2].getType()+ "   "+p[0][3].getType()+ "   "+p[0][4].getType()+ "  "+p[0][5].getType()+ "   "+ "   "+p[0][6].getType()+ "   "+p[0][7].getType()+ "   "+p[0][8].getType()+ "   "+p[0][9].getType()+" 10");
            System.out.println("9  "+p[1][0].getType()+ "   "+p[1][1].getType()+p[1][2].getType()+ "   "+p[1][3].getType()+ "   "+p[1][4].getType()+ "  "+p[1][5].getType()+ "   "+ "   "+p[1][6].getType()+ "   "+p[1][7].getType()+ "   "+p[1][8].getType()+ "   "+p[1][9].getType()+" 9");
            System.out.println("8  "+p[2][0].getType()+ "   "+p[2][1].getType()+p[2][2].getType()+ "   "+p[2][3].getType()+ "   "+p[2][4].getType()+ "  "+p[2][5].getType()+ "   "+ "   "+p[2][6].getType()+ "   "+p[2][7].getType()+ "   "+p[2][8].getType()+ "   "+p[2][9].getType()+" 8");
            System.out.println("7  "+p[3][0].getType()+ "   "+p[3][1].getType()+p[3][2].getType()+ "   "+p[3][3].getType()+ "   "+p[3][4].getType()+ "  "+p[3][5].getType()+ "   "+ "   "+p[3][6].getType()+ "   "+p[3][7].getType()+ "   "+p[3][8].getType()+ "   "+p[3][9].getType()+" 7");
            System.out.println("6  "+p[4][0].getType()+ "   "+p[4][1].getType()+p[4][2].getType()+ "   "+p[4][3].getType()+ "   "+p[4][4].getType()+ "  "+p[4][5].getType()+ "   "+ "   "+p[4][6].getType()+ "   "+p[4][7].getType()+ "   "+p[4][8].getType()+ "   "+p[4][9].getType()+" 6");
            System.out.println("5  "+p[5][0].getType()+ "   "+p[5][1].getType()+p[5][2].getType()+ "   "+p[5][3].getType()+ "   "+p[5][4].getType()+ "  "+p[5][5].getType()+ "   "+ "   "+p[5][6].getType()+ "   "+p[5][7].getType()+ "   "+p[5][8].getType()+ "   "+p[5][9].getType()+" 5");
            System.out.println("4  "+p[6][0].getType()+ "   "+p[6][1].getType()+p[6][2].getType()+ "   "+p[6][3].getType()+ "   "+p[6][4].getType()+ "  "+p[6][5].getType()+ "   "+ "   "+p[6][6].getType()+ "   "+p[6][7].getType()+ "   "+p[6][8].getType()+ "   "+p[6][9].getType()+" 4");
            System.out.println("3  "+p[7][0].getType()+ "   "+p[7][1].getType()+p[7][2].getType()+ "   "+p[7][3].getType()+ "   "+p[7][4].getType()+ "  "+p[7][5].getType()+ "   "+ "   "+p[7][6].getType()+ "   "+p[7][7].getType()+ "   "+p[7][8].getType()+ "   "+p[7][9].getType()+" 3");
            System.out.println("2  "+p[8][0].getType()+ "   "+p[8][1].getType()+p[8][2].getType()+ "   "+p[8][3].getType()+ "   "+p[8][4].getType()+ "  "+p[8][5].getType()+ "   "+ "   "+p[8][6].getType()+ "   "+p[8][7].getType()+ "   "+p[8][8].getType()+ "   "+p[8][9].getType()+" 2");
            System.out.println("1  "+p[9][0].getType()+ "   "+p[9][1].getType()+p[9][2].getType()+ "   "+p[9][3].getType()+ "   "+p[9][4].getType()+ "  "+p[9][5].getType()+ "   "+ "   "+p[9][6].getType()+ "   "+p[9][7].getType()+ "   "+p[9][8].getType()+ "   "+p[9][9].getType()+" 1");
        }}
    Thank in you advance! :)

  2. #2
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: Non static method printBoard(boolean) cannot be referenced from a static context

    You're trying to access printBoard(true) as though its a static function when actually its a member function.

    Is p[][] a member variable or a static variable?

  3. #3
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: Non static method printBoard(boolean) cannot be referenced from a static context

    You'll have to do one of the following:
    1. Create an object of type StrategoBoard and access printBoard through that object, i.e.

    Java Code:
    StrategoBoard strategoBoard = new StrategoBoard();
    strategoBoard.printBoard(true);
    for this case the p[][] must be a member variable or if its a static variable, it must be accessed with the Class name, e.g. StrategoBoard.pp[0][0].

    2. or, change the printBoard function to a static function, i.e.

    Java Code:
    public static void printBoard(boolean printSolution) {
    In this case p[][] must be a static variable.

    Stephen

  4. #4
    warp is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Re: Non static method printBoard(boolean) cannot be referenced from a static context

    Thank you very much!

Similar Threads

  1. Replies: 1
    Last Post: 11-17-2011, 07:21 AM
  2. Replies: 9
    Last Post: 06-10-2011, 01:40 AM
  3. Replies: 4
    Last Post: 04-16-2011, 06:15 PM
  4. Replies: 7
    Last Post: 05-19-2010, 12:12 PM
  5. Replies: 1
    Last Post: 08-07-2007, 06:05 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •