Java 用向量填充二维数组时的NullPointerException

Java 用向量填充二维数组时的NullPointerException,java,arrays,vector,multidimensional-array,Java,Arrays,Vector,Multidimensional Array,我有一点问题,我似乎无法解决。我试图用for循环中的向量填充数组(因为向量的大小会随时间而变化)。 我在一个名为StudentFactory的类中创建了这样的向量: private Vector<StudentImpl> theListOfStudents = new Vector<StudentImpl>(); private Vector thelistofstudens=new Vector(); 并将其传递给名为表的类,如下所示: public Vector&

我有一点问题,我似乎无法解决。我试图用for循环中的向量填充数组(因为向量的大小会随时间而变化)。 我在一个名为StudentFactory的类中创建了这样的向量:

private Vector<StudentImpl> theListOfStudents = new Vector<StudentImpl>();
private Vector thelistofstudens=new Vector();
并将其传递给名为表的类,如下所示:

public Vector<StudentImpl> table() {
        return theListOfStudents;
    }
        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);
公共向量表(){
归还学生名单;
}
然后在表中类中,我尝试如下填充2D数组:

public Vector<StudentImpl> table() {
        return theListOfStudents;
    }
        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);
theFactory=StudentFactory.getInstance();
//创建列名称
字符串columnNames[]={“名称”,“地址”};
向量温度;
temp=factory.table();
//创建一些数据
字符串[][]数据;
对于(int i=0;i
它一直告诉我设置
字符串[][]数据
设置为null,但当我设置时,我会得到null引用指针。这里的任何帮助都会很好,谢谢

它一直告诉我设置字符串[][]数据;使无效

它并不是真的告诉你这些,而是数据还没有初始化

根据向量的大小,将数据设置为所需的大小:

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