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();
  while(GraphSize>0)
  {
      if(Graph.get(i).getChild().equals(ParentCH))
          break;
      i++;
      GraphSize--;
      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:
run:
21
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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.