简体   繁体   English

我收到此错误消息并了解原因:不能应用于给定类型; 必需:未找到增强:int,int

[英]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.对于上下文,我正在尝试获取用户的输入,然后将其插入并将其与 2D 数组中的值进行比较。

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: a.isValid 正在抛出错误消息:

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. isValid() 没有声明任何参数,但是您传递了两个整数。 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.您的isValid方法不需要任何 arguments,但无论如何您都尝试将其传递 2 int 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.这样,它实际上可以获取您的int并处理它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 方法不能应用于给定类型 必需:int。 发现:没有 arguments - Method cannot be applied to given types Required: int. Found: no arguments 我正在尝试交换两个值,同时运行代码时出现此错误“不兼容的类型。找到:&#39;int&#39;,需要:&#39;int[]&#39;” - I'm trying to swap two values , while running the code im getting this error " Incompatible types. Found: 'int', required: 'int[]' " 出现“运算符‘&&’不能应用于‘布尔值’、‘int’”错误,我不确定为什么 - Getting an "Operator '&&' cannot be applied to 'boolean', 'int'" error and I'm unsure why 错误:类型不兼容:可能从int到short的有损转换。 我不知道为什么我收到此错误消息 - error: incompatible types: possible lossy conversion from int to short. I don't know why i'm getting this error message 不兼容的类型:可能从double到int的有损转换。 我不知道为什么我收到此错误消息 - incompatible types: possible lossy conversion from double to int. I don't know why i'm getting this error message 我的代码出现错误:不兼容的类型:int无法转换为布尔线:6 - I'm getting an error for my code: incompatible types: int cannot be converted to boolean line:6 错误消息“运算符'&&'无法应用于'int''boolean' - Error message "Operator '&&' cannot be applied to 'int' 'boolean' 错误信息:运算符 &lt; 不能应用于 boolean,int - Error message: operator < cannot be applied to boolean,int 为什么需要int? Java 错误:发现双精度,需要整数 - Why is an int required? Java Error: Found double, required int 错误:不兼容的类型:消息无法转换为 int? - Error: incompatible types: Message cannot be converted to int?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM