Nullpointer with scheduler

Discussion in 'Plugin Development' started by arjanforgames, Aug 12, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    arjanforgames

    Hey,

    Im executing a piece of code every minute but it gives me an error.
    Every minute, when the code should execute, the error pops up in my console.

    This is my error:
    Code:
    [12:35:58 WARN]: [*CENSORED*] Task #49 for *CENSORED* v0.1 generated an except
    ion
    java.lang.NullPointerException
            at me.arjanforgames.*CENSORED*.WeatherHandler.run(WeatherHandler.java:1
    5) ~[?:?]
            at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftTask.run(CraftTask.java
    :71) ~[spigot.jar:git-Spigot-1604]
            at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftScheduler.mainThreadHea
    rtbeat(CraftScheduler.java:350) [spigot.jar:git-Spigot-1604]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:6
    41) [spigot.jar:git-Spigot-1604]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    89) [spigot.jar:git-Spigot-1604]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    84) [spigot.jar:git-Spigot-1604]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :490) [spigot.jar:git-Spigot-1604]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [spigot.jar:git-Spigot-1604]
    >
    This is my code:
    Code:java
    1. public void run() {
    2. String weatherState = "";
    3. World world = Bukkit.getWorld("MineCompany");
    4. long serverTime = world.getTime();
    5.  
    6. if(serverTime < 6000 && serverTime > 0){
    7. Random rand = new Random();
    8. int weatherType = rand.nextInt(2) + 1;
    9.  
    10. switch(weatherType){
    11. case 1: weatherState = "sunny";
    12. world.setStorm(false);
    13. break;
    14. case 2: weatherState = "stormy";
    15. world.setStorm(true);
    16. break;
    17. default: weatherState = "regular";
    18. break;
    19. }
    20.  
    21. Bukkit.broadcastMessage("[" + ChatColor.GREEN + "NEWS" + ChatColor.WHITE + "] " + "Today will be a " + weatherState + " day!");
    22. }
    23. }


    And its called in "onEnable" like this:
    Code:java
    1. getServer().getScheduler().scheduleSyncRepeatingTask(this, new WeatherHandler(), 20L*5, 20L*60);
     
  2. Offline

    guangong4

    Show the full class, because I need to know which line is lone 15 (where the error is occurring)
     
  3. Offline

    Tecno_Wizard

    arjanforgames, can you post the entire class? I cannot determine the line of the error with the class header missing.
     
  4. Offline

    fireblast709

    Aww, Spigot (not supported on this forum)
     
  5. Offline

    arjanforgames

    Weather Handler
    Code:java
    1. package me.arjanforgames.*CENSORED*;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.World;
    8.  
    9. public class WeatherHandler implements Runnable{
    10.  
    11. @Override
    12. public void run() {
    13. String weatherState = "";
    14. World world = Bukkit.getWorld("MineCompany");
    15. long serverTime = world.getTime();
    16.  
    17. if(serverTime < 6000 && serverTime > 0){
    18. Random rand = new Random();
    19. int weatherType = rand.nextInt(2) + 1;
    20.  
    21. switch(weatherType){
    22. case 1: weatherState = "sunny";
    23. world.setStorm(false);
    24. break;
    25. case 2: weatherState = "stormy";
    26. world.setStorm(true);
    27. break;
    28. default: weatherState = "regular";
    29. break;
    30. }
    31.  
    32. Bukkit.broadcastMessage("[" + ChatColor.GREEN + "NEWS" + ChatColor.WHITE + "] " + "Today will be a " + weatherState + " day!");
    33. }
    34. }
    35.  
    36. }
    37.  
     
  6. Offline

    Necrodoom

    arjanforgames unofficial builds are not supported here. Seek support where you got your build.
     
  7. Offline

    arjanforgames


    I don't think it has anything to do with Spigot.
     
  8. Offline

    Tecno_Wizard

    I can try,

    Line 15 is throwing a null pointer exception:

    Code:java
    1. World world = Bukkit.getWorld("MineCompany");
    2. long serverTime = world.getTime();//Line throwing error


    I would expect that your problem is likely caused by the first line here, for Null Pointer specifies that you are trying to access a value that does not exist. Are you sure the world's name is MineCompany? Also, just because it isn't CraftBukkit doesn't mean we don't help the guy people!
    ( I will try to continue to help, but don't expect immediate responses, I have a life!)
     
  9. Offline

    Necrodoom

    Tecno_Wizard if he doesn't use craftbukkit he should ask in the proper support forums for his build.
     
  10. Offline

    Tecno_Wizard

    Necrodoom, I agree with that, but he came here looking for help and I'm not going to deny that.
     
  11. Offline

    Iroh

    Locked.
    Seek help where you acquired your server mod.
     
Thread Status:
Not open for further replies.

Share This Page