I have this very simple code:
public class Player{
private int x,y,velX,velY,width,height,id;
private boolean isControllable;
public Player(int _x,int _y,int _width,int _height,int _id,boolean _cont){
x = _x;
y = _y;
width = _width;
height = _height;
id = _id;
isControllable = _cont;
if(_cont == true){
addToCont();
}
}
private void addToCont(){
Main.controllable.add(this);
}
}
And this:
public class Main {
public static Render render = new Render();
public static Controlls controll = new Controlls();
public static LinkedList<Player> controllable;
public static void main(String[] args) {
controllable = new LinkedList<Player>();
render.height = 750;
render.width = 1000;
render.RenderWindow();
}
}
As You can see I am trying to add this instance of player class to the linked list. But it returns an error:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
at game.Player.Player.addToCont(Player.java:23)
at game.Player.Player.<init>(Player.java:18)
at game.Main.Render.<init>(Render.java:28)
at game.Main.Main.<clinit>(Main.java:9)
What am I doing wrong?