Multiple config files don't work. Line 16 returning Nullpointer

Discussion in 'Plugin Development' started by stimoze, Dec 16, 2017.

Thread Status:
Not open for further replies.
  1. Hi! Currently i'm trying to clean up my code a little bit, im trying to make separate config files, but this keeps returning a nullpointer exception, and i can't find out why.


    This is the log
    Code:
    [01:57:12] [Server thread/ERROR]: Error occurred while enabling GoldenHub-PvP v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at com.stimonz.pvpsystem.ConfigurationUtil.loadBountyYaml(ConfigurationUtil.java:16) ~[?:?]
        at com.stimonz.pvpsystem.Main.onEnable(Main.java:25) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[minecraft_server.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [minecraft_server.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [minecraft_server.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [minecraft_server.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [minecraft_server.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [minecraft_server.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [minecraft_server.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [minecraft_server.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [minecraft_server.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [minecraft_server.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_101]
    This is my class
    Code:
    public class ConfigurationUtil {
        public static Main m = new Main();
      
        public static FileConfiguration bounty;
        public static FileConfiguration lifeguard;
        public static FileConfiguration cfgvoid;
      
        public static void loadBountyYaml(){
              16. line>  bounty = YamlConfiguration.loadConfiguration(new File(m.getDataFolder(), "bounty.yml"));
        }
      
        public static void loadLifeguardYaml(){
                lifeguard = YamlConfiguration.loadConfiguration(new File(m.getDataFolder(), "lifeguard.yml"));
        }
      
        public static void loadVoidYaml(){
                cfgvoid = YamlConfiguration.loadConfiguration(new File(m.getDataFolder(), "void.yml"));
        }
      
        public static FileConfiguration getBountyYaml(){
            return bounty;
        }
      
        public static FileConfiguration getLifeguardYaml(){
            return lifeguard;   
        }
      
        public static FileConfiguration getVoidYaml(){
            return cfgvoid;
        }
    }
    Thanks for helping!
     
  2. Offline

    Caedus

    Code:
    public static Main m = new Main();
    Never instantiate a new instance of your main class (the one that extends JavaPlugin). This could well be your problem, perhaps 'm' is null.
     
  3. Offline

    AdamDev

    @stimoze
    When making an instance of your main class never do "Main m = new Main();", that's only for other classes.

    - The proper way to do it make a static variable in your main class that is set to nothing. Make sure its private.
    - Then make a public static method that returns your variable.
    - After inside of another class, make a variable such as: "Main m = Main.getInstance();", replace "getInstance()" with whatever returns your plugin in your main class.

    Another thing is that do you have any method that creates the files?, Do you have any methods that save your files?
    Try making those methods. If the problem persists, it could be something that it can't load the data file because maybe you hadn't created it yet.
     
Thread Status:
Not open for further replies.

Share This Page