0

These are snippets of my code, but I keep getting the same error and I have no idea why.

I keep getting

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2

at Grammar.(Grammar.java:92)

I can see that it has to do with the array size, maybe, but I have no idea where.

Thank you in advance if someone can help me, it would be greatly appreciated.

public int getInit() {
        return init;
    }

int max = 100;
    int[][] ntr = new int[max][0];

NTR tempo = nttemp.remove(0); // NTR is another class that contains only gets
            int tempoF = tempo.getFirst();
            int tempoS = tempo.getSecond();


int i = 1;
92 ntr[tempo.getInit() - 'A'][i] = tempoF;
i++;
ntr[tempo.getInit() - 'A'][i] = tempoS;
i++;
V3loz4
  • 1
  • 1
  • Please [edit] your question and post the entire stack trace you are getting. Also post the text that is line 92 in file `Grammar.java`. – Abra Sep 14 '20 at 18:09

1 Answers1

1

You create a zero sized array of arrays. Whenever you try to subscript that, it will be out of bounds since there are no valid indices for a zero length array (whatever the type).

user268396
  • 11,576
  • 2
  • 31
  • 26
  • Even making it not Zero it still gives out the same error. and in that case I wanted to create a list, but I need it also to be a 2d array. – V3loz4 Sep 15 '20 at 17:20