简体   繁体   中英

I'm getting this error message and understand why: cannot be applied to given types; required: no augments found: int, int

This may be a lack of sleep situation but I cannot figure out why I'm getting this message, I know it'll be a simple fix but I cannot wrap my head around it, any help is appreciated.

For context, I'm trying to take the user's input and then plug that in and compare that to the values in a 2D array.

This is the array I'm trying to compare

String[][] board = {{"-", "-", "-", "-", "-", "-", "-", "-"},
    {"-", "-", "-", "-", "-", "-", "-", "-"},{"-", "-", "-", "-", "-", "-", "-", "-"},
    {"-", "-", "-", "-", "-", "-", "-", "-"},{"-", "-", "-", "-", "-", "-", "-", "-"},
    {"-", "-", "-", "-", "-", "-", "-", "-"},{"-", "-", "-", "-", "-", "-", "-", "-"},
    {"-", "-", "-", "-", "-", "-", "-", "-"}};
public void makeMove() {
    Scanner choice = new Scanner(System.in);
    System.out.println("Enter the row");
    int tempCol = choice.nextInt();

    System.out.println("Now the column");
    int tempRow = choice.nextInt();

    // a.setPiece(tempRow, tempCol, "W");
    a.isValid(tempRow, tempCol);
}

a.isValid is throwing out the error message:

method isValid in class board cannot be applied to given types;
    required: no arguments
    found: int, int
    reason: actual and formal argument lists differ in length

And this is the method I'm trying to communicate with:

public void isValid() {
    if (board[tempRow][tempCol] = "W") {
        display();
    } else {
        System.out.println("Move invalid, try again");
        makeMove();
    }
}

This also throws out a different error message but I'm going to create a new question for that

isValid() does not have any parameters declared, but your are passing two ints. Did you mean to declare it like this?

public void isValid(int tempRow, int tempCol){
    if(board[tempRow][tempCol] = "W"){
        display();
    } else {
        System.out.println("Move invalid, try again");
        makeMove();
    }
}

Your isValid method doesn't take any arguments, but you try to pass it 2 int s anyways. You'll have to change your declaration to say:

public void isValid(int tempRow, int tempCol){

That way it can actually take your int s and process them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM