简体   繁体   English

Java:方法不适用于参数

[英]Java: Method is Not Applicable for Arguments

Okay. 好的。 So, I'm a kid, trying to program a cool little 3d game, and then this... issue decides to take a crap on my next few days. 因此,我还是一个孩子,试图编写一个很棒的3D小游戏,然后这个问题决定我接下来的几天不高兴。

I'm using Eclipse for my IDE. 我将Eclipse用于我的IDE。 When I insert controls.tick(forward, back, left, right, turnLeft, turnRight); 当我插入controls.tick(forward, back, left, right, turnLeft, turnRight); ("controls" is, well, the controls for my game, and "tick" is the time which ties into steps, turning, time itself, etc.) Eclipse says "The method 'tick'(boolean, boolean, boolean, boolean, boolean) in the type 'Controller' is not applicable for the arguments (boolean, boolean, boolean, boolean, boolean, boolean)" and I'm beginning to get incredibly frustrated. (“ controls”是我游戏的控件,“ tick”是连接到步,转弯,时间本身等的时间。)Eclipse表示"The method 'tick'(boolean, boolean, boolean, boolean, boolean) in the type 'Controller' is not applicable for the arguments (boolean, boolean, boolean, boolean, boolean, boolean)"并且我开始感到非常沮丧。 "forward, back, left, right, turnLeft, turnRight" are booleans designed to, well, be booleans, and prevent the camera from moving. “向前,向后,向左,向左,向右,向左转,向右转”是布尔型,旨在使布尔型成为可能,并防止相机移动。 They are "linked" to keys that set it to true, to keep this short. 它们被“链接”到将其设置为true的键,以保持简短。 "Controller" is a .class file to "house" the controls, rotations, etc. “控制器”是一个.class文件,用于“容纳”控件,旋转等。

So, what's an in-depth response of what I'm doing wrong? 那么,对我做错了什么的深入回应? It's important I don't add or take away any booleans from what I have. 重要的是我不要从我所拥有的中添加或删除任何布尔值。 Is there any way around this, and may I have a walkthrough? 有什么办法可以解决这个问题,我可以进行演练吗?

Here is my .class file that does the work: 这是我的.class文件,可以正常工作:

package com.mime.ocelot;

import java.awt.event.KeyEvent;

import com.mime.ocelot.input.Controller;

public class Game {

public int time;
public Controller controls;

public Game() {

}

public void tick(boolean[] key) {
    time++;
    boolean forward = key[KeyEvent.VK_W];
    boolean back = key[KeyEvent.VK_S];
    boolean left = key[KeyEvent.VK_A];
    boolean right = key[KeyEvent.VK_D];
    boolean turnLeft = key[KeyEvent.VK_LEFT];
    boolean turnRight = key[KeyEvent.VK_RIGHT];

    controls.tick(forward, back, left, right, turnLeft, turnRight);

}

}

And here's the .class that is the actual controller: 这是实际控制器的.class:

package com.mime.ocelot.input;

public class Controller {

public double x, z, rotation, xa, za, rotationa;

public void tick(boolean forward, boolean back, boolean right, boolean turnLeft, boolean turnRight) {

}

}

tick() is defined like this: tick()的定义如下:

tick(boolean forward, boolean back, boolean right, boolean turnLeft, boolean turnRight)

It takes five boolean arguments. 它需要五个布尔参数。 You call it like this: 您这样称呼它:

tick(forward, back, left, right, turnLeft, turnRight);

You're trying to pass it six boolean arguments. 您正在尝试向其传递六个boolean参数。 It looks like you meant to define it like this: 看起来您打算像这样定义它:

tick(boolean forward, boolean back, boolean left, boolean right, boolean turnLeft, boolean turnRight)

Wow, I got six upvotes for pointing out that a parameter was missing in a function definition. 哇,我指出了函数定义中缺少参数的情况,得到了六次赞成。

尽管您传递了6,tick方法签名期望5个布尔值。将tick方法更改为:

public void tick(boolean forward, boolean back, boolean left, boolean right, boolean turnLeft, boolean turnRight)

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

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