Array Index Out of Bounds Exception

2012-09-17  Source: Original Site  Category:Java  Views:1 


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;
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++)
System.out.println("vertex "+array[i]);

the error that i get is

returned from absgraph
printing # of vertex 4
array size 4
vertex a
vertex b
vertex c
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at AbsGraph.readInput(
at DriverProgram.main(

----jGRASP wedge2: exit code for process is 1.

what fuction should i use?

Related articles
  • Array Index Out of Bounds Exception 2012-09-17

    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 no

  • Array Index Out of bound exception-11670 2012-09-26

    I am working with xml ,jsp,java. I need to go to jsp page from a sevlet and while I am doing that I get this aray index out of bound exception-11670. [2/6/08 10:57:37:631 EST] 00000033 SystemOut O INSBDriver.execute(useWebService) [2/6/08 10:57:37:63

  • Keep getting array index out of bounds exception 2012-05-31

    Hi, I am having a rather bizarre problem here. See i keep getting this out of bounds exception when I execute this piece of code: //Above, scanner 's' declared/initialized, treemap 'itemPriceMap' declared/initialized ---------------------------------

  • Array index out of bound me to remove it 2012-04-29

    package sha; import; /** * * @author deepak */ public class Sha { public static void main(String[] args) throws Exception{ MessageDigest sha = MessageDigest.getInstance("SHA-1"); byte [] i1 = args[0].getBytes("UTF8"); sha.

  • Array Index Out Of Bounds Exception: 0? 2013-01-13

    I'm somewhat new to Java and programming in general and I am receiving this error when I run my program and I have zero idea as to what is causing it. Thanks in advance. public class AssignmentEight {static final String INFILE_NAME = "ass8_input.txt"

  • AIX 5.3.8 pSeries JKD 1.6 SR 7 - Array Index Out of Bound Exception 2013-12-10

    All the static data are wiped off from memory, including cache variable. The below code fails after few runs with ArrayIndexOutofBound Exception. Say v is a vector new vector created from string if( v.size() > 4 ) String newString = (String) v.ele

  • Array Index out of bound Exception 2014-01-21

    I got Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at this line. File f1= new File(args[0]); I guess i have to give a command line argument. How to give a file as command line argument. Or is this someother one?

  • Oracle Fusion Security, SearchResponse next returning array index out of bound 2013-10-16

    I am trying to fetch all the roles under a search base and while iterating i am getting array index out of bound exception. SimpleSearchFilter filter=store.getSimpleSearchFilter(RoleProfile.NAME,SimpleSearchFilter.TYPE_EQUAL,null); String wildCardCha

  • {System.Runtime.Inte ropServices.External Exception} = Array index out of bounds 2014-04-07

    I am trying to import mails from Outlook to my Database during execution of code it is throwing the "Excepiton ComException unhandeled by User Code" Array index out of bounds. it was working fine in the biggening but suddenly start throwing this exce

  • String Index out of bounds exception ?? 2014-04-18

    I am writing a program for a class that implements a parser for a given grammar. I have already successfully written it in c++ and now I have to also write it in java. The string to be parsed is a string array in my program and when I try to run it,

  • Getting Array Index out of bound error, help please 2014-06-02

    So I'm suppose to create some code that will perform some methods in recursion. Here's the prompt: Assignment #9 will be the construction of a program that reads in a sequence of numbers (not necessary integers) from standard input until 0 is read, a

  • Array Index Out Of Bounds?? 2014-12-27

    I've recently come upon a frustrating Array Index Out Of Bounds error when selecting any of the "calculations" to be applied to the entered values(maximum 1000 values). I suspect it to be a problem with the values[(c+1)] in the for loop. I can't figu

  • string Index out of bounds exception and printing array values 2014-08-29

    Below are the instructions for what I am currently working on. I am having 2 problems first is printing the values stored in my array right now i have it set up in a for loop but there seems to be something wrong with the syntax of my System.out stat

  • String Trim Program, Array Index Out of Bound Error. Please Help 2013-01-03

    /** * @(#) * Program to trim any space at the end of a string * * @author Marshall * @version 1.00 2010/3/10 */ public class TrimEndSpaces { static String trim(String s) { char chr[] = s.toCharArray(); int i=0; int length = chr.leng

  • jdbc -> progress String index out of bounds exception 2015-05-22

    I'm trying to connect to the progress db through jdbc. But I get the java.lang.StringIndexOutOfBoundsException Can anybody please help me?!? I'm using progress v9.1 and the JdbcProgressDriver! Very much thanks in advance! This is my script: public sn

  • Please Help with ERROR: Array out of bounds exception 2013-07-15

    why does "Array out of bounds exception" error occur when tryin to complie

  • DGL0392A: Index out of bound 2012-03-07

    I am submitting an E-Form. There are 5 attributes. And the maximum length of nonDisplayName of an attribute is 20. CM FixPack level is 8. Now please tell me that what I have to do. Because I am unable to submit the E-Form. The exception is: "DkExcept

  • listview problem: index out of bounds 2016-09-08

    I am trying to dynamically check/uncheck listview column headers through a menu bar. This is working only if go in a serial order. But if I do this in a random fashion, it pops up the message- index out of bounds. How can I take care of this? I need

  • .NET "Index Out Of Range" exception when using "MAX" 2012-04-23

    I'm using the .NET connector, version in VB9. When I attempt to use the MAX query, it throws an "Index Out Of Range" exception. This is the query: (SELECT MAX(PALNUMEXT) FROM woreporting where PALNUMDATE = '9015' AND TRANSTYPE = 'X3 SEND' AN

  • help: memory out of bound exception 2013-03-13

    Hi, I'm a please be gentle Sorry if my post is a little bit innapropriate... I got a problem... I'm building a java-based Bayesian email filtering. The filters require training set for the learning phase. It require to store every word co