I am getting a null pointerexception and I am not sure why.
I tried debuging it by adding a system.out.print statement like so:
System.out.println(GameKeys.mouse[pointer]+"-"+pointer);
The output from this statment was: "null-0"
Error
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.ia.df.manager.GameInputProcessor.touchDown(GameInputProcessor.java:34)
at com.badlogic.gdx.backends.lwjgl.LwjglInput.processEvents(LwjglInput.java:300)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:200)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Gamekeys class:
public class GameKeys {
public static final int MAX_FINGERS = 2;
public static Vector3[] mouse = new Vector3[MAX_FINGERS]; // x & y
public static boolean[] down = new boolean[MAX_FINGERS];
public static boolean[] pdown = new boolean[MAX_FINGERS];
public static boolean isDownT(int i) {
return down[i];
}
public static boolean isPressedT(int i) {
return down[i] && !pdown[i];
}
public static boolean isReleasedT(int i) {
return !down[i] && pdown[i];
}
public static void update() {
for (int i = 0; i < MAX_FINGERS; i++) {
pdown[i] = down[i];
}
}
}
GameInputProcessor class:
public class GameInputProcessor extends InputAdapter {
public boolean touchDown(int x, int y, int pointer, int button) {
if(pointer > GameKeys.MAX_FINGERS - 1)
return true;
System.out.println(GameKeys.mouse[pointer]+"-"+pointer);
// out is GameKeys.mouse[pointer] is null
GameKeys.mouse[pointer].set(x, y, 0);
GameKeys.down[pointer] = true;
return true;
}
}
game class:
// when user touch left side of screen than do some thing
for (int i = 0; i < GameKeys.MAX_FINGERS; i++) {
if (GameKeys.isPressedT(i)) {
if (GameKeys.mouse[i].x < Gdx.graphics.getWidth() / 2) {
// do some thing
}
}
}