I'm new to java programming and I can't find a solution to my problem. I think it's a pretty easy problem but I can't figure a what I'm doing wrong so I hope one of you could help me. The problem is when I try to store some data in an array it returns the following error:
Exception in thread "main" java.lang.NullPointerException
Code
public class FetchData{
private String rows[][];
private int rowCount;
public FetchData(){
rowCount = 0;
}
public boolean ConnectAndFetch(String start, String end){
//not relevant to the problem
for(...){
List<WebElementdivList = driver.findElements(By.tagName("div"));
int divCount = 0;
int colCount = 0;
for (WebElement elem : divList) {
if(divCount 24){
if(colCount < 17){
System.out.println(elem.getText());
//System.out.println(colCount);
//System.out.println(rowCount);
rows[rowCount][colCount] = elem.getText();
colCount++;
} else {
rowCount += 1;
colCount = 0;
}
}
divCount++;
}
}
return true;
}
I think it has something to do with the declaration private String rows[][];
but I don't know how to fix it. I'd appreciate your help!
You need to initialize your rows
array first before you can store values in it:
String[][] rows = new String[10][10];
Use any size you need. I chose 10
randomly. I suggest initializing the array in your class constructor.