Please close this - I only just noticed this is on the wrong topic

Discussion in 'Spigot Help' started by Blubo, Jan 7, 2020.

Thread Status:
Not open for further replies.
  1. So today I wanted to write a "simple" shop plugin but I ran into this hell of an exception and I don't know how to fix it.

    The line in question is:
    Code (Java):
    if (item_names.get(i).contains("/")) {
    The sorrounding code is following:
    Code (Java):
    for (int i = 0; i < ItemManager.items.get(name).size(); i++) {
                if (item_names.get(i).contains("/")) {
                    String[] split = item_names.get(i).split("/");
                    String[] split2 = items_pre.get(item_names.get(i)).split("/");

                    List<String> test = new ArrayList<String>();

                    test.add("§7§lPreis: §c" + split2[0]);
                    test.add("§7§lVerkaufen fuer: §c" + split2[1]);

                    ItemStack item = new ItemStack(Material.valueOf(split[0]), 1, Short.valueOf(split[1]));
                    ItemMeta item_m = item.getItemMeta();
                    item_m.setLore(test);
                    item.setItemMeta(item_m);

                    inv.setItem(i, item);
    To explain this - so you can better undstand what I'm trying to do.

    I have an ItemManager which has a few lists in it (including item_names (ArrayList) and items_pre (HashMap))
    Every entry in item_names is just the name of the variable of the item in Material#
    Example: Entry in my list: IRON_INGOT
    Result in Material#: Material.IRON_INGOT
    items_pre are just the Items with the buy / sell values and metadatas as well as the Material# variable
    attached.
    Example: Entry in my list: Key: STONE/1 <- the 1 being the metadata (in this case granite)
    Variable: 25(buy value)/15(sell value)
    In this case the list item_names has 17 Entrys.

    The Exception is following:
    Code (Text):
    Caused by: java.lang.IndexOutOfBoundsException: Index: 17, Size: 17
            at java.util.ArrayList.rangeCheck(ArrayList.java:657) ~[?:1.8.0_201]
            at java.util.ArrayList.get(ArrayList.java:433) ~[?:1.8.0_201]
            at me.blubo.development.events.InventoryClickEventHandler.prepareInv(InventoryClickEventHandler.java:121) ~[?:?]
            at me.blubo.development.events.InventoryClickEventHandler.onClick(InventoryClickEventHandler.java:86) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_201]
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_201]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_201]
            at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_201]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            ... 15 more
     
    If any questions about my code remain - please feel free to ask.
    Thanks for reading and I hope you can help me.
     
  2. I just noticed that this is the wrong section - sorry for that. Can you please tell me how I move it? Thanks
     
  3. Go to the response and press "More Options..." then put any reply you want then uncheck the "Open" under the chatbox. Somewhere below here, I don't have it because I'm not the author of the post. But you will have it. Then create another thread in the correct forum.
    upload_2020-1-7_22-4-6.png
     
Thread Status:
Not open for further replies.