为什么';不能在JAVA中调用方法(单个示例)
我在和LeapMotion合作。我的主类中有以下代码:为什么';不能在JAVA中调用方法(单个示例),java,methods,Java,Methods,我在和LeapMotion合作。我的主类中有以下代码: public void onFrame(Controller controller) { Frame frame = controller.frame(); GestoPistola gesto; if (!frame.hands().isEmpty()) { System.out.println("ENTER"); gesto.reconocer(frame);
public void onFrame(Controller controller) {
Frame frame = controller.frame();
GestoPistola gesto;
if (!frame.hands().isEmpty())
{
System.out.println("ENTER");
gesto.reconocer(frame);
}
…
}
然后,这是GestoPistola类,这是一个必须完成所有工作的类
public class GestoPistola {
public enum ESTADO{
DESCARGADA, CARGADA
}
ESTADO _estado;
public void GestoPistola(){
_estado = ESTADO.DESCARGADA;
}
public void reconocer(Frame f)
{
System.out.println("LET'S START");
if (!f.hands().isEmpty()) {
System.out.println("Hay mano");
Hand hand = f.hands().get(0);
FingerList fingers = hand.fingers();
switch(_estado)
{
…
}
}
}
}
因此,控制台显示“回车”,但从不显示“让我们开始”
我知道这是一个非常简单的问题,但我不是JAVA方面的专家
希望有人能帮助我 您从不初始化
gesto
,因此当您尝试调用reconcer
时,可能会遇到NullPointerException
改变
GestoPistola gesto;
到
您从不初始化gesto变量,因此存在NullPointerException
改变
GestoPistola gesto代码>到GestoPistola gesto=new GestoPistola()代码>您可能在第gesto.recocer(帧)行中有一个空指针异常代码>,对吗?就是这样!谢谢!
GestoPistola gesto = new GestoPistola ();