mercredi 7 novembre 2018

Getting an error when calling on a method from within an if statement (Java)

Info:

  • My program takes an input and draws a board using this input
  • I have two classes, my main class and my Board class
  • In my board class, I have two methods, drawBoard and Scanner

Problem:

So right now I call on my method Scanner which takes an input, then call on my method Board which draws the board. This works great the first time but I want it to keep calling on those methods continuously. I wrote the following code:

public static void main(String[] args) {

    Main m = new Main();
    Board b = m.new Board();

    if{!complete){
        b.drawBoard();
        b.Scanner();
    }

}

But for some reason, drawBoard and Scanner turn red and it says "Cannot resolve method 'drawBoard()' " and the same for Scanner. When b.drawBoard() and b.Scanner() are not inside the if statement there's no problem. Does anyone know why this is happening and how I can continuously call on these two methods? Thanks in advance for any help.

Aucun commentaire:

Enregistrer un commentaire