Search code examples
javamavennullpointerexceptionbukkit

Unknown error in Bukkit 1.8 plugin with Maven


I always get a java.lang.NullPointerException when trying to activate my Spigot plugin. I didn't find any errors, but maybe you can help me. Server output:

[13:36:25] [Server thread/ERROR]: Error occurred while enabling UnitedShops v0.0.3 (Is it up to date?)
java.lang.NullPointerException
    at io.github.nexadn.unitedshops.config.ConfigShopMain.parseConfig(ConfigShopMain.java:45) ~[?:?]
    at io.github.nexadn.unitedshops.shop.GUIContainer.initGUI(GUIContainer.java:25) ~[?:?]
    at io.github.nexadn.unitedshops.UnitedShops.onEnable(UnitedShops.java:41) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-f94fe8f-2642f9b]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-f94fe8f-2642f9b]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-f94fe8f-2642f9b]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:356) [spigot.jar:git-Spigot-f94fe8f-2642f9b]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:316) [spigot.jar:git-Spigot-f94fe8f-2642f9b]
    at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-f94fe8f-2642f9b]
    at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-f94fe8f-2642f9b]
    at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-f94fe8f-2642f9b]
    at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-f94fe8f-2642f9b]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:524) [spigot.jar:git-Spigot-f94fe8f-2642f9b]
    at java.lang.Thread.run(Thread.java:745) [?:1.7.0_85]

ConfigShopMain.java:

// imports, package, etc...    
public class ConfigShopMain extends ConfigBase {
    private HashMap<String, ShopInventory> menus;       // Menu container

    public ConfigShopMain(File file) {
        super(file);
        menus = new HashMap<String, ShopInventory>();
    }
    public ConfigShopMain(File file, String mainTag)
    {
        super(file, mainTag);
        menus = new HashMap<String, ShopInventory>();
    }
    // parse the Config File 
    public void parseConfig()
    {
        Set<String> kies = super.getSubKeys();
        for( String s:kies )
        {
            String title = super.getMainSection().getString(s + ".title"); // shops.[key].title
            Material icon = Material.getMaterial(super.getMainSection().getString(s + ".iconitem")); // shops.[key].iconitem
            this.menus.put(s, new ShopInventory(title, new ItemStack(icon, 1)) );
            String sect = super.getWorkKey() + "." + s + "." + "items";
            Set<String> subkies = super.getConf().getConfigurationSection(sect).getKeys(false);
            for( String sub:subkies ) // shops.[key].items.[key2]
            {
                ConfigurationSection sec = super.getConf().getConfigurationSection(sub);
                Material mat = Material.getMaterial(sec.getString("item")); // shops.[key].items.[key2].item // ERROR ??? //
                ShopObject cont = new ShopObject(mat, sec.getDouble("buy"), sec.getDouble("sell")); // Shop Contents
                this.menus.get(s).addContent(cont);
            }
        }
    }

    public List<ShopInventory> getMenus() 
    {
        List<ShopInventory> temp = null;
        Collection<ShopInventory> inv = this.menus.values();
        temp = (List<ShopInventory>) inv;
        return temp;
    }
}

Thank you for your feedback. (GitHub repo: http://github.com/NexAdn/unitedshops/)


Solution

  • It looks that sec is null. It is possible that you made some typos.