Running this file returns the error:
Exception in thread "main" java.lang.NullPointerException
at Packet.<init>(test.java:20)
at test.main(test.java:46)
here:
line 20 : this.data[j] = data[j];
line 46 : Packet packet = new Packet(4,data,count,column);
can anyone help ma how to create this constructor that accepts String[][] ?
class Packet{
int op_code;
String[][] data;
int column;
int count;
String type ;
Packet(int op_code, String[][]data, int count, int column){
data = new String[100][10];
this.op_code = op_code;
this.column = column;
for(int i=0; i<count; i++)
{
for(int j=0; j<column; j++)
{
this.data[i][j] = data[i][j];
}
}
type = "string[][]";
this.count = count;
}
}
public class test {
public test() {
}
public static void main(String[] args) {
int count = 3;
int column = 3;
String[][] data = new String[3][3];
data[0][0] = "00";
data[0][1] = "01";
data[1][1] = "11";
Packet packet = new Packet(4,data,count,column);
}
}
actually the purpose of this constructor was to deliver a database resultset to client which is done else where and works ok with creating String[][] data. but when i use the Packet() constructor , i get a null exception.
thank you.