Solved NullPointerException i don't understand

Discussion in 'Plugin Development' started by Robin Bi, Aug 17, 2014.

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

    Robin Bi

    So when starting the server with my current plugin i always get this error: http://hastebin.com/qekuwuzaqe.avrasm

    Normally i'm using Spigot but the error on top was thrown using craftbukkit and using spigot does not change it. However, let's get more into the error.


    It tells me, an NPE is thrown when going through Main.java:49. What's in there?
    Code:java
    1. Config.config.loadConfig();

    in the method "onEnable()" that we all know ;)

    And my config class looks like this:
    Code:java
    1. public class Config {
    2.  
    3. public static Config config;
    4.  
    5. public void loadConfig() {
    6.  
    7. Main.plugin.getConfig().addDefault("Locations.Lobby.World", "World");
    8. Main.plugin.getConfig().addDefault("Locations.Lobby.X", 0);
    9. Main.plugin.getConfig().addDefault("Locations.Lobby.Y", 0);
    10. Main.plugin.getConfig().addDefault("Locations.Lobby.Z", 0);
    11.  
    12. Main.plugin.getConfig().addDefault("Settings.Using Bungeecord", false);
    13. Main.plugin.getConfig().addDefault("Settings.Lobby Server Name", "lobby 1");
    14.  
    15. Main.plugin.getConfig().addDefault("Settings.MinPlayers", 10);
    16. Main.plugin.getConfig().addDefault("Settings.MaxPlayers", 20);
    17.  
    18. Main.plugin.getConfig().addDefault("Settings.Award", 300);
    19.  
    20. Main.plugin.getConfig().options().copyDefaults(true);
    21. Main.plugin.saveConfig();
    22. }
    23. }


    Well this is only the loadConfig() method and there are some more, but Main.java:49 calls this particular method.

    Now in loadConfig() I'm just setting Defaults. The only thing i "get" is the config from Main.plugin, so that should be the only thing that is able to throw an NPE, right?
    If so, why does it throw an NPE? getConfig() should always return the standard FileConfiguration of "config.yml" in the plugin folder!?


    I just don't see why there's an NPE and that's why i can't fix it. Maybe someone can put me in the right way.


    ~Robin Bi
     
  2. Offline

    teej107

    Your NPE is occurring because you haven't initialized your config object. You would have known this if you didn't make your Config object static.
     
  3. Offline

    Rocoty

    You are not assigning any value to the public static Config config field.
     
  4. Offline

    Robin Bi

    Rocoty teej107 Oh ya, guess i just were blind... Changed, it! Thanks, guys :)
     
Thread Status:
Not open for further replies.

Share This Page