Hey there! any question in your mind? Ask It Now!.

Popular Categories





Exception: java.lang.ArrayIndexOutOfBounds

+6 votes
346 views
asked in Programming by jatin Expert (3,823 points)

i am using a array and with a loop aading the items in array like this :

public ArrayList<String> Items(){
    ArrayList<String> objItemList = new ArrayList<String>();
    Sheet objSheet = this.objExcel.getSheet("path");
    for(int i=1;i <= objSheet.getRows();i++){
        
        objItemList.add("A"+i);
        
   }

}

but getting this exception

java.lang.ArrayIndexOutOfBoundsException: 7

Thanks For help!

1 Answer

+1 vote
answered by Himanshu Expert (5,940 points)
selected by jatin
 
Best answer
Give row count with -1 in loop like this

  for(int i=1;i <= objSheet.getRows()-1;i++){
        
        objItemList.add("A"+i);
        
       }

So your code will be

public ArrayList<String> Items(){
ArrayList<String> objItemList = new ArrayList<String>();
 Sheet objSheet = this.objExcel.getSheet("path");
 for(int i=1;i <= objSheet.getRows()-1;i++){
        
        objItemList.add("A"+i);
        
            }

            }

This will help you out if you face any problem let me know!

Related Questions

+3 votes
1 answer 85 views
–1 vote
0 answers 145 views
+2 votes
1 answer 84 views
0 votes
0 answers 73 views
+2 votes
1 answer 122 views
+4 votes
1 answer 61 views
+7 votes
8 answers 7,422 views
+1 vote
2 answers 1,597 views
0 votes
0 answers 110 views
0 votes
0 answers 181 views
asked in Programming by vimal jain

Not a Member yet?

Ask to Folks Login

My Account
436 Folks are online
2 members and 434 guest online
Your feedback is highly appreciated