Solved Converting a List to a Set

Discussion in 'Spigot Plugin Development' started by DevRice, Jun 2, 2017.

  1. Hello! I am trying to convert a list from a YAML file and convert that into a Set and then take that Set and place it into a HashMap<String, Set<String>>. It seems just fine when I convert it, the error is popping up when I try putting it into the Map.

    Code (Text):
    for(String name : inventoryNames){
                    Set<String> membersRef = new HashSet<>(inventoriesRef.getStringList("inventories." + name + ".members"));
                    Set<String> ownersRef = new HashSet<>(inventoriesRef.getStringList("inventories." + name + ".owners"));
                    Set<String> officersRef = new HashSet<>(inventoriesRef.getStringList("inventories." + name + ".officers"));
                    String inventoryRef = inventoriesRef.getString("inventories." + name + ".inventory");

                        members = new HashMap<>();
                    members.put(name, membersRef); //ERROR HERE
                        owners = new HashMap<>();
                    owners.put(name, new HashSet<>(ownersRef));
                        officers = new HashMap<>();
                    officers.put(name, new HashSet<>(officersRef));
                    if(inventoryRef == null)
                        inventories = new HashMap<>();
                    inventories.put(name, inventoryRef);
    Error message:

    Code (Text):
        at io.github.collabstorage.CollabStorage.onEnable( ~[?:?]
        at ~[craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin( [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugin( [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugins( [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at org.bukkit.craftbukkit.v1_11_R1.CraftServer.reload( [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at org.bukkit.Bukkit.reload( [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at org.bukkit.command.defaults.ReloadCommand.execute( [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at org.bukkit.command.SimpleCommandMap.dispatch( [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand( [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchServerCommand( [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at net.minecraft.server.v1_11_R1.DedicatedServer.aM( [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at net.minecraft.server.v1_11_R1.DedicatedServer.D( [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at net.minecraft.server.v1_11_R1.MinecraftServer.C( [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at [craftbukkit-1.11.2.jar:git-Bukkit-6e3cec8]
        at [?:1.8.0_111]
    Any help is greatly appreciated! Thank you.
    #1 DevRice, Jun 2, 2017
    Last edited: Jun 2, 2017
  2. what's the error?
  3. Oops, I'll edit my original post
  4. I didn't read the whole code but you may do this to convert easily
    Code (Java):
    List<String> list = new ArrayList<String>();
    Set<String> set = new Set<String>(list);
  5. debug name and membersref
  6. I did that, the issue is when I try to put that new set into a hashmap.
  7. also check if inventoryNames is not null before having loop on it.
  8. I have that, I just didn't post all my code.
  9. how about debugging? if the list is created successfully and if the sets are not null.
  10. If you mean check if they are not null, I did, they are perfectly fine. I'm not too sure why it's not working..
  11. then members is null (the map itself)
  12. I mean debug
    Code (Java):
    List<String> list = new ArrayList<>();
    System.out.print("created successfully");
  13. Oh god. I'm such an idiot.. I set the map as null... Thank you hahaha(nervous laugh)
  14. the same you did at inventoryRef and also mark the thread as solved.