Two-dimensional string storage declaration, Exception in thread & ldquo; hand & rdquo; java.lang.NullPointerException java


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


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
            List<WebElementdivList = driver.findElements(By.tagName("div"));

            int divCount = 0;
            int colCount = 0;
            for (WebElement elem : divList) {
                if(divCount 24){
                    if(colCount < 17){
                        rows[rowCount][colCount] = elem.getText();
                    } else {
                        rowCount += 1;
                        colCount = 0;
        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.