Results 1 to 2 of 2
  1. #1
    kool001 is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Post Array Index Out of Bounds Exception

    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.

    Java Code:
    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

    Java Code:
    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.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

Similar Threads

  1. [SOLVED] Array index out of bounds exception
    By sruthi_2009 in forum New To Java
    Replies: 6
    Last Post: 03-23-2014, 10:16 AM
  2. New to Java, Arrays- index out of bounds
    By Connorhj in forum New To Java
    Replies: 8
    Last Post: 12-02-2009, 09:22 PM
  3. Array Index Out of bound exception
    By abhijit in forum Networking
    Replies: 7
    Last Post: 09-25-2009, 07:25 PM
  4. Array out of bounds exception 20.
    By dropt in forum New To Java
    Replies: 4
    Last Post: 09-21-2009, 10:32 PM
  5. Array Index out of bounds
    By leapinlizard in forum New To Java
    Replies: 5
    Last Post: 04-29-2009, 05:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •