如何在不等式中使用浮点数

时间:2015-11-02 04:01:19

标签: java android libgdx

您好我的代码给了我以下错误:

Error:(116, 23) java: method isPulled in class com.testrr.pizzadeliverymadness.Lever cannot 
be applied to given types;
  required: float
  found: no arguments
  reason: actual and formal argument lists differ in length

这是导致所有麻烦的if语句的一部分:

chefY > 0f

chefYfloat(我猜?),我是通过使用精灵Y位置得到的:

以下是我用来设置chefY的代码:

chefY = Boyardee.getY();

我不知道为什么会收到此错误,有人可以看一下吗?

编辑:这是整个Lever课程:

package com.zacharyweiss.pizzadeliverymadness;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;

/**
 * Created by zachw on 10/25/15.
 */
public class Lever extends Button {
    public Lever (Texture texture) {super(texture);}

    public boolean isPulled(float chefY) {

        if(Gdx.input.isTouched()
           && Gdx.graphics.getHeight() - Gdx.input.getY() >= this.getY() 
           && this.getHeight() <= this.getY() + this.getHeight()
           && this.getWidth() >= Gdx.input.getX() && chefY > 0f)
        {
            return true;
        }

        return false;
    }
}

该函数由简单的if语句

调用
if (GreenLever.isPulled()) {
    Boyardee.setTexture(new Texture("Photos/ChefGreen.png"));
}

我现在得到了一个N​​ullPointerException,如下所示:

   2015-11-01 20:46:15.018 java[3455:235609] 20:46:15.018 WARNING:  140: This application, or a library it uses, is using the deprecated Carbon Component Manager for hosting Audio Units. Support for this will be removed in a future release. Also, this makes the host incompatible with version 3 audio units. Please transition to the API's in AudioComponent.h.
Exception in thread "LWJGL Application" java.lang.NullPointerException
    at com.zacharyweiss.pizzadeliverymadness.InGameScreen.<init>(InGameScreen.java:34)
    at com.zacharyweiss.pizzadeliverymadness.PizzaDeliveryMadness.create(PizzaDeliveryMadness.java:67)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:143)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)

1 个答案:

答案 0 :(得分:2)

您已撰写isPulled(),因此需要float作为参数。当您尝试调用它时,不会向其传递任何参数。而不是:

if (greenLever.isPulled())

没有向isPulled()传递任何参数,做这样的事情:

float x = //whatever you want it to equal
if (greenLever.isPulled(x) {
    Boyardee.setTexture(new Texture("Photos/ChefGreen.png"));
}