Solved NPE at Startup. None if /reload

Discussion in 'Plugin Development' started by L33m4n123, Sep 15, 2013.

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

    L33m4n123

    Hey guys.

    if I start my local server to test my plugin I get a NPE

    Show Spoiler

    Code:
    18:40:12 [SEVERE] Could not load 'plugins\cookieclicker.jar' in folder 'plugins'
     
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:182)
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:305)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:230)
            at org.bukkit.craftbukkit.v1_6_R2.CraftServer.loadPlugins(CraftServer.ja
    va:239)
            at org.bukkit.craftbukkit.v1_6_R2.CraftServer.<init>(CraftServer.java:21
    7)
            at net.minecraft.server.v1_6_R2.PlayerList.<init>(PlayerList.java:56)
            at net.minecraft.server.v1_6_R2.DedicatedPlayerList.<init>(SourceFile:11
    )
            at net.minecraft.server.v1_6_R2.DedicatedServer.init(DedicatedServer.jav
    a:106)
            at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    :391)
            at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    82)
    Caused by: java.lang.NullPointerException
            at com.github.l33m4n123.cookieclicker.CookieClicker.<init>(CookieClicker
    .java:30)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
     
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:178)
            ... 9 more

    and the plugin wont load. So. If I do a /reload however. The Plugin loads fine.

    IF I understand the stacktrace correct the NPE is at my CookieClicker class at line 30.

    Here are my lines 29,30 and 31

    Show Spoiler

    Code:java
    1. private ScoreboardManager manager = Bukkit.getScoreboardManager(); // line 29
    2. private Scoreboard board = manager.getNewScoreboard(); // line 30
    3. private Objective objective = board.registerNewObjective("test", "dummy"); // line 31


    So. What confueses me. Why does it throws a NPE if I do a regular start up but works fine if I reload the server via console while noone is online

    More infos:

    My onEnable()
    Show Spoiler
    Code:java
    1. @Override
    2. public void onEnable() {
    3. // TODO Insert logic to be performed when the plugin is enabled
    4. getServer().getPluginManager().registerEvents(this, this);
    5. cookieCheck();
    6. }


    the function cookieCheck();
    Show Spoiler
    Code:java
    1. public void cookieCheck() {
    2. this.getServer().getScheduler()
    3. .scheduleSyncRepeatingTask(this, new BukkitRunnable() {
    4. public void run() {
    5. // Do stuff
    6. int roundCps = (int) Math.round(cookiePerSecond);
    7. int newScore = cookie.getScore() + roundCps;
    8. cookie.setScore(newScore);
    9. }
    10. }, 100L, 100L);
    11. }


    The .bat file of how I start my server
    Show Spoiler

    java -Xmx1024M -Xms1024M -jar craftbukkit-1.6.2-R1.0.jar

    Anyone any tips?
     
  2. Offline

    Technius

    L33m4n123
    Perhaps Bukkit's ScoreboardManager is initialized before the plugins are enabled, but after the plugins are loaded. Try initializing those three variables inside of onEnable.
     
  3. Offline

    L33m4n123

    Technius

    Cheers. Solved my issue. Should have checked that earlier.. Can rewrite about 5 hours of work.. lol
     
Thread Status:
Not open for further replies.

Share This Page