hellow every one
im facing problem in my coad wich i tried to understand what is the mistake
of my symantic but no progress.....
this is the code

private static void NNA(ArrayList<triple> Graph,String GoalN)
  ArrayList<triple> vp= new ArrayList<triple>(100);

  int index=0;// the index of the nodes in the visited path
  String ParentCH ="&";// this chrecter is in the array and i want to find the index of this char.
  int i=0;
  Boolean FoundGN=false;
  Boolean Dublication=false;
  int GraphSize=Graph.size();
      System.out.println(" i="+i+" and graph size ="+GraphSize);

      ParentCH=Graph.get(i).getChild();//here is the line that generate the error

this is the errors that appear:
i=1 and graph size =20
i=2 and graph size =19
i=3 and graph size =18
i=4 and graph size =17
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 21, Size: 21
i=5 and graph size =16
i=6 and graph size =15
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
i=7 and graph size =14
at java.util.ArrayList.get(ArrayList.java:322)
i=8 and graph size =13
at ai_assignment.Main.NNA(Main.java:82)
i=9 and graph size =12
at ai_assignment.Main.main(Main.java:50)
i=10 and graph size =11
i=11 and graph size =10
i=12 and graph size =9
i=13 and graph size =8
i=14 and graph size =7
i=15 and graph size =6
i=16 and graph size =5
i=17 and graph size =4
i=18 and graph size =3
i=19 and graph size =2
i=20 and graph size =1
i=21 and graph size =0
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

if i didnt do the output it gives me array index out of bound...
the chrecter & is at index 3.....is there any problem considring my comparison?
please any help...i want to undersatnd whats going on
thank you in a dvance.

5 Years
Discussion Span
Last Post by JamesCherrill

You go through the loop (lines 13-19) and do not find a match, so you fall out of the loop with i=21, size=0
Then on line 21 you execute Graph.get(i) with i still equal to 21. The valid indexes are 0-20, so there's your error.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.