Inventory[] set and get inventories

Discussion in 'Plugin Development' started by MexMaster, Jan 24, 2014.

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

    MexMaster

    Hey,
    i tried to set a new Inventory (created with Bukkit.createInventory()) into my Inventory[]...
    everytime i try to access the inventory name or either set the inventoryit returns a NullPointerException (it points at something not there... but what?!)

    Exception:
    Code:
    java.lang.NullPointerException
        at me.MexMaster.MinigameGUI.Managers.MinigameGUI_Manager.initalizeInventorys(MinigameGUI_Manager.java:205) ~[?:?]
        at me.MexMaster.MinigameGUI.Main.onEnable(Main.java:65) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:218) ~[craftbukkit.jar:git-Spigot-1232]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457) [craftbukkit.jar:git-Spigot-1232]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:385) [craftbukkit.jar:git-Spigot-1232]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin(CraftServer.java:302) [craftbukkit.jar:git-Spigot-1232]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.enablePlugins(CraftServer.java:284) [craftbukkit.jar:git-Spigot-1232]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.reload(CraftServer.java:639) [craftbukkit.jar:git-Spigot-1232]
        at org.bukkit.Bukkit.reload(Bukkit.java:279) [craftbukkit.jar:git-Spigot-1232]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:24) [craftbukkit.jar:git-Spigot-1232]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:196) [craftbukkit.jar:git-Spigot-1232]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:546) [craftbukkit.jar:git-Spigot-1232]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchServerCommand(CraftServer.java:533) [craftbukkit.jar:git-Spigot-1232]
        at net.minecraft.server.v1_7_R1.DedicatedServer.aw(DedicatedServer.java:309) [craftbukkit.jar:git-Spigot-1232]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:274) [craftbukkit.jar:git-Spigot-1232]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:540) [craftbukkit.jar:git-Spigot-1232]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:446) [craftbukkit.jar:git-Spigot-1232]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Spigot-1232]
    here are some code snippets (if you wan't more ask, but i think it's not needed)

    my onEnable()
    Code:java
    1. @Override
    2. public void onEnable() {
    3.  
    4. System.out.println("----------[MinigameGUI]---------");
    5.  
    6. configFile = new File(getDataFolder(), "config.yml");
    7.  
    8. getCommand("mg").setExecutor(new MinigameGUI());
    9. getCommand("minigamegui").setExecutor(new MinigameGUI());
    10.  
    11. new InventoryClick(this);
    12. new PlayerInteract(this);
    13.  
    14. try {
    15. firstRun();
    16. } catch (Exception e) {
    17. e.printStackTrace();
    18. }
    19.  
    20. config = new YamlConfiguration();
    21.  
    22. loadYamls();
    23.  
    24. mginv = Bukkit.createInventory(null, config.getInt("rows") * 9, config.getString("minigame_inventory_name"));
    25.  
    26. MinigameGUI_Manager.loadInventory();
    27. MinigameGUI_Manager.initalizeInventorys();
    28. MinigameGUI_Manager.loadCustomInventorys();
    29.  
    30. System.out.println(" MinigameGUI activated!");
    31. System.out.println(" Author: MexMaster");
    32. System.out.println(" Version: 1.0.0");
    33. System.out.println("--------------------------------");
    34.  
    35. }


    my initializeInventorys (yeah i wrote it wrong i think):
    Code:java
    1. public static void initalizeInventorys() {
    2.  
    3. int currInv = 0;
    4.  
    5. while(Main.config.isSet("other_menus." + currInv)){
    6.  
    7. !HERE IS THE ERROR! Main.invens[currInv] = Bukkit.createInventory(null, Main.config.getInt("other_menus." + currInv + ".rows") * 9, Main.config.getString("other_menus." + currInv + ".inventory_name"));
    8.  
    9. currInv++;
    10.  
    11. }
    12.  
    13. }


    and this is how i defined my Inventory[] thing...

    Code:java
    1. public static Inventory[] invens;


    hope anybody can help or has a workaround
    btw. i'm not sure if Inventory[] should be used :/

    lg
     
  2. Offline

    Jakeob22

    I would recommend using an ArrayList to store the inventories. You could use this to initialize it:

    Code:java
    1. public static ArrayList<Inventory> invens = new ArrayList<Inventory>();


    and use this to add to it:

    Code:java
    1. invens.add(inventory);


    I don't really see where you're putting inventories to your Inventory[] in your code?
     
  3. Offline

    MexMaster

    oh damn i forgot about arraylists [pig]
    Thanks, man seems like i'm to long programming today... i can't see a tree in the forest :D

    really thanks ;)
     
Thread Status:
Not open for further replies.

Share This Page