I am gettin ArrayIndex Out of bound exception ! | Selenium Forum
M
Posted on 30/01/2017
Hi,
I am getting array outofbound index exception
My code is below , can you please have a look at this I am not sure where I am going wrong .
Kindly help !

package Rough;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import Utilities.Base_class;
public class ExcelPackage extends Base_class {
@Test(dataProvider = "getdata")
public void testa(String username, String pass ,String email , String phonenumber)


{
System.out.println(username+pass+email+phonenumber);
}
@DataProvider
public Object[][] getdata()

{
//Xls_Reader(System.getProperty("user.dir")+""//src");
Xls_Reader xls = new Xls_Reader("C://Workspace3//Parks_Victoria//src//Data//TestSuiteData.xlsx");
int noofrows = xls.getRowCount("regtest");
System.out.println(noofrows);
int Columncount = xls.getColumnCount("regtest");
System.out.println(Columncount);
Object data[][] = new Object[noofrows][Columncount];
int dataRow =0;
for(int x = 0; x <= noofrows;x++)
{
for (int y =0; y<Columncount;y++)
{

data[dataRow][y]= xls.getCellData("regtest", y, x);
System.out.print(xls.getCellData("regtest", y, x));
System.out.print("-------------------------------");
}
System.out.println();
dataRow++;
}
return data ;

}
}

M
Replied on 30/01/2017

In the for loop, replace [b:28rci520][u:28rci520]x <= noofrows[/u:28rci520][/b:28rci520] with [u:28rci520][b:28rci520]x < noofrows[/b:28rci520][/u:28rci520]