Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Open Source Projects
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Other Open Source Projects
Query on null pointer Exception
akshitha Akki
Greenhorn
Posts: 24
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
package library; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.concurrent.TimeUnit; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.openqa.selenium.By; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import test.SeleneseTest; public class TestDataprovider extends SeleneseTest { @Test(dataProvider = "testData") public void testLogin(String uname, String pword) { driver.manage().timeouts().implicitlyWait(2000,TimeUnit.SECONDS); driver.get("http://yahoomail.com"); driver.findElement(By.id("username")).sendKeys("uname"); driver.findElement(By.id("passwd")).sendKeys("pword"); boolean res = driver.findElement(By.id("persistent")).isSelected(); System.out.println(res + "----------------"); if(res == true) driver.findElement(By.id("persistent")).clear(); else { driver.findElement(By.id("persistent")).click(); driver.findElement(By.id("persistent")).click(); } driver.findElement(By.xpath("//*[@id='.save']")).submit(); WebDriverWait wait = new WebDriverWait(driver, 90); wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("yucs-logo_link")))); System.out.println("done"); } @DataProvider public Object[][] testData() //public void testData() { Object data[][] = new Object[2][]; String str[][]= new String[2][]; Properties prop = System.getProperties(); System.out.println(prop.getProperty("java.class.path", null)); // to get the class path XSSFWorkbook workbook = null; String url = "C:\\Trial_workspace\\testProject\\resources\\data.xlsx"; try { workbook = new XSSFWorkbook(new FileInputStream(url)); int sheetNumber = workbook.getNumberOfSheets(); XSSFSheet sheet = workbook.getSheetAt(0); String sheetName = sheet.getSheetName(); Iterator<Row> rowIterator = sheet.iterator(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); int rows = 0; Iterator<Cell> cellIterator = row.cellIterator(); int colms = 0; while(cellIterator.hasNext()) { Cell cell = cellIterator.next(); switch(cell.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: //System.out.println(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_NUMERIC: //System.out.println(cell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: //System.out.println(cell.getStringCellValue()); if (colms == 0) str[rows][colms] = cell.getStringCellValue(); //System.out.println(cell.getStringCellValue()); if (colms == 1) str[rows][colms] = cell.getStringCellValue(); //System.out.println(cell.getStringCellValue()); break; } colms ++; } rows ++; System.out.println(""); } } catch (FileNotFoundException e) { e.printStackTrace(); System.out.println("FileNotFoundException"); } catch (IOException e) { e.printStackTrace(); System.out.println("IOException"); } return data; } }
I am getting Nullpointer exception. could someone please help in letting me know how to fix it.
Paul Clapham
Marshal
Posts: 28193
95
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
First step is to find out what line of code is throwing the exception. The stack trace will tell you that -- and I see that your code is printing the stack trace for you.
(This isn't a Scala question, so I'm moving it to a better forum.)
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
reading xlsx example issue
Error while reading Excel file.
How to read .xlsx sheet from Client Side using poi 3.5
java.lang.NoClassDefFoundError: org/dom4j/DocumentException - error encontered
How do i format a string to date
More...