I have a run() method that runs every second and it has to pass data (such as the current time in seconds since the start of the timer) to a method in a different class 'Spawner'.
Run method:
@Override
public void run() {
counter++;
if(Main.running[0] == true)
{
color = "Red";
spawn = "base";
world = "world";
Spawner spawnerObject = new Spawner();
spawnerObject.loadSpawner(counter, spawn, color, world);
run[0]++;
if(run[0] == 30)
{
Main.running[0] = false;
run[0] = 0;
}
}
}
I'm not sure but the NPE I get at 'spawnerObject.loadSpawner(counter, spawn, color, world);' can only have its origin at the spawnerObject.
All I want is run that method every second but I can't figure out how to call the non static method from 'Spawner'. This is the method:
public void loadSpawner(Integer counter, String spawner, String color, String world)
{ //code
}
Please can someone tell me how to invoke that method? My current thing with the spawnerObject is probably terribly wrong.
Error/Stacktrace:
[10:39:24] [Server thread/WARN]: [ColorKeyBattle] Task #5 for ColorKeyBattle v1.0 generated an exception
java.lang.NullPointerException
at org.Ziron5.main.Spawner.loadSpawner(Spawner.java:79) ~[?:?]
at org.Ziron5.main.TimerClass.run(TimerClass.java:59) ~[?:?]
at org.bukkit.craftbukkit.v1_8_R1.scheduler.CraftTask.run(CraftTask.java:71) ~[start.jar:git-Spigot-952179b-43207df]
at org.bukkit.craftbukkit.v1_8_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [start.jar:git-Spigot-952179b-43207df]
at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:698) [start.jar:git-Spigot-952179b-43207df]
at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [start.jar:git-Spigot-952179b-43207df]
at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [start.jar:git-Spigot-952179b-43207df]
at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [start.jar:git-Spigot-952179b-43207df]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_40]
Complete loadSpawner()
Method:
It's quite a long method so I put it on pastebin: http://pastebin.com/iDNDSQQc