1.12.2 Why do I get an error when I create/access my yml files

Discussion in 'Spigot Plugin Development' started by Soccercraft, May 1, 2020.

  1. Code (Text):
     [Server thread/ERROR]: Error occurred while enabling FarmingTiers v1.0 (Is it up to date?)
    java.lang.NullPointerException: null
        at me.DuncanGaming.FarmingTiers.PlayerData.<init>(PlayerData.java:14) ~[?:?]
        at me.DuncanGaming.FarmingTiers.FarmingTiers.onEnable(FarmingTiers.java:28) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:381) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:330) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:422) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:383) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:338) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_241]
    I keep on getting errors, specifically the "Is it up to date", and null pointer exceptions when enabled, when I attempt to create my custom yml file. I followed a guide exactly, but I continue to get errors in my main class when I attempt to get the class that all of my config.set() methods are in. And I get errors in my file configuration class. Line 14 in file config, and Line 28 in main.
    Code (Java):
    private FarmingTiers main;
    //Line 14
    File playerYml = new File(main.getDataFolder()+"/playerdata.yml");

        FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(playerYml);
    Code (Text):
        private FarmCommand farmGUI;
        private PlayerData setPlayerMeta;
        private BlockData setBlockMeta;
        private static FarmingTiers instance;
        public CommandManager commandManager;

        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
            // Line 28 setPlayerMeta = new PlayerData(this);
     
    #1 Soccercraft, May 1, 2020
    Last edited: May 1, 2020
  2. Have you created the file yet? Or does the directory exist?
     
  3. The "Is it up to date?" is just because the plugin failed to load, not relevant to the error itself.

    Like fujiboy4 said, check the file exists, is in the right place, and named correctly. Docs say getDataFolder() shouldn't return nulls, so it's likely the File constructor throwing the NPE because the path is invalid.
     
  4. I created the file in the src folder, where the plugin.yml is, I guess I haven't created the file yet? How would I go about doing that?
     
  5. Wouldn't you want it to create your file in the plugins folder? I don't think you can create files inside a jar file once the file has been exported from eclipse/java.
     
    • Agree Agree x 1
  6. Oh ok, so just do an if the file doesn't exist, then create it check?
     
  7. Yes. And like I was saying before, I don't think you can create files inside your jar file once it's been exported. So you'll need to use your plugins folder to create your files (or other locations, just not your jar file).