I have an excel sheet having 10 entries , 0-9 rows & 0 columns. I want to read a random value from the cell of (5,0) ex (row, column) using random function ? Below is the code i tried !
FileInputStream fis = new FileInputStream("C://Users//logasaravanan.g//Desktop//seleniumtest.xls");
HSSFWorkbook wb = new HSSFWorkbook(fis);
HSSFSheet sheet = wb.getSheet("xxxx");
Random rand = new Random();
int a= rand(sheet.getLastRowNum());
HSSFRow row = sheet.getRow(a);
System.out.println("Running test case " + row.getCell(0).toString());
You use nextInt
Your error lies in the fact that you try to use your rand
Object
as a method.That's not how it works. Your rand is a
Object
of the type RandomYou then access methods ON that object to achieve your goals. You can kinda see it as a toolbox.
By doing
Random rand = new Random()
you're getting your toolbox off the shelf. Then you can use tools that are IN the toolbox, likerand.nextInt