Well, here i m trying store the some vertices(4) in an array. and trying to read them. But i m getting an error of "Array Index out of Bounds Exception.
I know the error is in the line i have highlighted(red). And i have tried various methods. But not working.
public void readInput()
{
Scanner input = null;
try
{
input = new Scanner(new FileInputStream("Test1.txt"));
int vertex = input.nextInt();
System.out.println("printing # of vertex "+vertex);
String[] array = new String[vertex];
System.out.println("array size "+ array.length);
// reading vertex from file and storing them in the array
for(int i=0;i<=array.length;i++)
{
array[i]=input.nextLine();
System.out.println("vertex "+array[i]);
}
the error that i get is
returned from absgraph
printing # of vertex 4
array size 4
vertex
vertex a
vertex b
vertex c
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at AbsGraph.readInput(AbsGraph.java:80)
at DriverProgram.main(DriverProgram.java:12)
----jGRASP wedge2: exit code for process is 1.
what fuction should i use?