Solved itemparser error

Discussion in 'Spigot Plugin Development' started by Ggamer55, Apr 14, 2017.

Thread Status:
Not open for further replies.
  1. i have a error with this item parser
    Code (Text):
        public ArrayList<ItemStack> parseItems(String rawitems) {
            ArrayList<ItemStack> ret = new ArrayList<ItemStack>();

            String[] a = rawitems.split(":");
            for (int i = 0; i < a.length; i++) {
                String b = a[i];
                String[] c = b.split(",");
                String itemid = c[0];
                String itemamount = c[1];
                ItemStack nitem = new ItemStack(Integer.parseInt(itemid), Integer.parseInt(itemamount));
                ret.add(nitem); //in this line have the error
            return ret;
    the error are a arrayindexofoutboundsexception: 0
  2. PD: i don't make it, i am making a fork from that plugin
  3. c is empty, b.split probably has no commas therefore it's empty. You're trying to get an index from c of [0] and [1] if those indexes don't exist then you'll get an indexOutOfBounds.

    Ret.addItem will never throw a null pointer because it is accessing an array list and it is adding not reading.

    Double check what line your error is on but I bet it's on [0] or [1]

    Sent from my iPhone using Tapatalk
  4. no, the error is in that line
  5. the error is this:
    Code (Text):
    [23:53:20 ERROR]: Error occurred while enabling TheSkywarsForked v1.0 (Is it up to date?)
    java.lang.ArrayIndexOutOfBoundsException: 0
            at us.sparknetwork.theskywarsfork.Main.parseItems( ~[?:?]
            at us.sparknetwork.theskywarsfork.Main.loadClasses( ~[?:?]
            at us.sparknetwork.theskywarsfork.Main.onEnable( ~[?:?]
    the line 1792 is:
    Code (Text):
  6. Can't be...

    Add system.out.printLn("b is: " + b)
    Put this right before string[] c = b.split

    Sent from my iPhone using Tapatalk
  7. it says
    b is: 5,64
    b is: 20,64
  8. So wooden planks and glass then the error occurs? Is there anything in the file this is reading from below where you find 5:64 and 20:64?

    Move your system.out up one line and change it to output the value of a please

    Sent from my iPhone using Tapatalk
  9. already solved lol, it solved alone
  10. i dont know why but it solved
Thread Status:
Not open for further replies.