NullPointerException when filling a 2Dimensional array with a vector

I have a bit of a problem that I cant seem to make work. Im trying to fill an array with a vector in a for loop(as the size of the vector will change over time). I create my vector like this in a class called StudentFactory:

private Vector<StudentImpl> theListOfStudents = new Vector<StudentImpl>();

and pass it to a class called table like this:

public Vector<StudentImpl> table() {
        return theListOfStudents;
    }

and then in the table class i try and fill the 2D array like this:

        theFactory  = StudentFactory.getInstance();

        // Create columns names
        String columnNames[] = { "Name", "Address"};
        Vector<StudentImpl> temp;
        temp = theFactory.table();
        // Create some data
        String [][] data;
        for(int i = 0; i < temp.size(); i++) 
        {
               data[i][0] = temp.get(i).getTheName();
               data[i][1] = temp.get(i).getTheAddress();
        }


        // Create a new table instance
        table = new JTable(data, columnNames);

It keeps telling me to set the String [][] data; to null but when i do i get the null reference pointer. Any help here would be great thanks

Answers


It keeps telling me to set the String [][] data; to null ...

It's not really telling you that, but rather that data has not yet been initialized.

Set data to the sizes it needs which is based on the size of your Vector:

String[][] data = new String[temp.size()][2];

Need Your Help

jQuery UI inside ajax div

jquery ajax jquery-ui

i have a site with links that look like this: onClick = ajax('link.html','contentdiv')

.NET MVC instantiate controller inside another controller

asp.net-mvc controller

Is it possible for an ASP.NET MVC controller to create a new instance of a different controller and effectively delegate resonsibility to that?