Hello, I have been trying to code a reaction based game for greenfoot which revolves around pressing buttons to create objects, which can be converted into spells. I am trying to calculate how many actors of a particular class there are in the world. I have looked up how to "getObjects" and the how to find their ".size"; however when adding the actor, which calculates all these objects, into the world it gives me :
java.lang.NullPointerException
at Invoker.NumbersE(Invoker.java:89)
at Invoker.<init>(Invoker.java:27)
int QuasNo = 0; int ExortNo = 0; int WexNo = 0; public Invoker() { NumbersE(); NumbersQ( ); NumbersW(); invoke(); Cast(); Animation(); } public void invoke(){ if(Greenfoot.isKeyDown("3")){ if (QuasNo == 3){ } if(ExortNo == 3){ } if(WexNo ==3 ){ } if(QuasNo == 2 && ExortNo == 1){ } if(QuasNo == 2 && WexNo == 1){ } if(ExortNo == 2 && WexNo == 1 ){ } if(ExortNo == 2 && QuasNo == 1 ){ } if(WexNo == 2 && ExortNo == 1 ){ } if(WexNo == 2 && QuasNo == 1 ){ } if(QuasNo == 1 && WexNo ==1 && ExortNo == 1){ } } } public void NumbersE(){ ExortNo = getWorld().getObjects(Exort.class).size(); } public void NumbersQ(){ QuasNo = getWorld().getObjects(Quas.class).size(); } public void NumbersW(){ WexNo = getWorld().getObjects(Wex.class).size(); }