Keys not adding to arrayList

Discussion in 'Plugin Development' started by pipo3090, May 27, 2017.

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

    pipo3090

    I have a config, in which some nodes in the form of numbers are stored. When I try to add them to a list, it doesn't give an error. But when I try to acces them, I get an NPE. I've done a little bit of debugging, and found out that the nodes are not added.

    Code:
    Code:
    public static void makeFoodInv(Player p, Core core){
           
            inv = Bukkit.createInventory(null, 9, "Eten");
           
            ConfigurationSection path = core.getConfig().getConfigurationSection("inv.eten");
           
            List<ConfigurationSection> itemList = new ArrayList<ConfigurationSection>();
           
            for(String key : path.getKeys(false)){
               
                itemList.add(path.getConfigurationSection(key));
               
            }
           
            for(int i = 0; i < itemList.size(); i++){
               
                p.sendMessage(itemList.get(i).toString()); // Here's the NPE
               
            }
           
            p.openInventory(inv);
           
        }
    
    If anyone can help, feel free to reply
     
  2. Offline

    timtower Administrator Administrator Moderator

    @pipo3090 Why not use the first loop to give all the items?
     
  3. Offline

    pipo3090

    Tried it without the list & in the 1st loop, now the output is zero for each one.
     
Thread Status:
Not open for further replies.

Share This Page