1

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());
  • this will help : http://stackoverflow.com/questions/363681/generating-random-integers-in-a-specific-range – cyboashu Dec 20 '16 at 08:23

1 Answers1

0

You use nextInt

int row = rand.nextInt(sheet.getLastRowNum());

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 Random

You 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, like rand.nextInt

Tschallacka
  • 27,901
  • 14
  • 88
  • 133
  • If this question helped you you can consider upvoting or accepting this answer, as an idication for future people having a similar problem that this solved your problem. – Tschallacka Dec 20 '16 at 10:39