Q:

ArrayIndexOutOfBoundsException generated when br.readLine() = ","

The code below has several functions which allow for things such as writing data to a document, reading it and putting the data in an array for a JTable later down the line.
package tabletest.populatetable;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class GetData {
    DataClass[] data = new DataClass[500];
    int nextPosition = 0;

    public GetData() {
        readData();
    }

    public void writeData()
    {
        try {
            BufferedWriter bw = new BufferedWriter(new FileWriter(new File("resources/tabledata.txt")));

            for(int i=0; i < nextPosition; i++) {
                bw.write(data[i].toString());
                bw.newLine();
            }

            bw.close();
        } catch(Exception e) {
            System.out.println("Invalid Data input");
        }
    }

    public void readData()
    {
        try {
            BufferedReader br = new BufferedReader(new FileReader(new File("resources/tabledata.txt")));
            String nextData = br.readLine();
            String[] arrayStringData;

            while (nextData != null) {

                try {
                    arrayStringData = nextData.split(",");
                } catch(NullPointerException nPE) {
                    arrayStringData = new String[] {" ", " "};
                }

                for(int i = 0; i < arrayStringData.length - 1; i++) {
                    if(arrayStringData[i] == null || arrayStringData[i] == "") {
                        arrayStringData[i] = " ";
                    }
                }

                DataClass getData = new DataClass();
                getData.col1 = arrayStringData[0].trim();
                getData.col2 = arrayStringData[1].trim();
                data[nextPosition] = getData;
                nextPosition++;
                nextData = br.readLine();
            }

            br.close();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public String[][] dataInTableForm() {
        final int colCount = 2;
        String[][] temp = new String[nextPosition][colCount];

        for(int i = 0; i < nextPosition; i++) {
            temp[i][0] = data[i].col1;
            temp[i][1] = data[i].col2;
        }

        return temp;
    }

    private class DataClass {
        String col1;
        String col2;

        public String toString() {
            return col1 + ", " + col2;
        }
    }
}

The document which it is reading, resources/tabledata.txt, is 12 lines long and it looks like this.
asfias, adsnj
aw,aerfae
aw,aewaa
,tre
asfd, 
okfas,af
e,ds
sw,f
,
asfias, adsnj
aw,aerfae
aw,aewaa

The problem is on line 9 of the text document. This is where it is just a , on its own. When there is something before or after the comma this seems to work fine and I checked by removing the line to see if it definitely was the comma causing the problem.
When I looked at the console I discovered the problem was a ArrayIndexOutOfBoundsException and the stack trace is below.
java.lang.ArrayIndexOutOfBoundsException: 0
    at tabletest.populatetable.GetData.readData(GetData.java:55)
    at tabletest.populatetable.GetData.<init>(GetData.java:14)
    at tabletest.Table.createTablePanel(Table.java:76)
    at tabletest.Table.createPanels(Table.java:34)
    at tabletest.Table.runGUI(Table.java:24)
    at tabletest.Table.main(Table.java:150)

Line 55 of the code is getData.col1 = arrayStringData[0].trim();
As you can see in the code I attempted several things to prevent this occurring but I have had no luck. I also tried removing the .trim() from the end of the line; however, exactly the same problem occurs.
I would appreciate any help in fixing this problem.

A:

Javadoc of split(String regex) says:

This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.

So, ",".split(",") will return an empty array, i.e. new String[0].
If you want to keep trailing empty strings, use ",".split(",", -1), which will return new String[] { "", "" }.

