I have created an array type pkt object of packet class to store a packet object pobj,and once passed to add method it is changed to dataInterest type and stored in the dlist[].....
In my code when i assign an object reference nodeobj[0].pkt[0]=pobj the error comes Exception in thread "main" java.lang.NullPointerException
at mhand.add(mhand.java:27)
at mhand.main(mhand.java:18)
i want to assign pkt[] for each nodeobj[0] and nodeobj[1].. so that each nodeobj has a unique pkt[] to store packet.public class mHand { public node[] nodeobj; public static void main(String[] args) { node[] nodeobj=new node[2]; nodeobj[0]=new node(1,2); nodeobj[1]=new node(6,6); packet pobj=new packet(3,0); mHand m=new mHand(); m.add(pobj); // ............................>line 18 } public void add(packet pobj) { nodeobj[0].pkt[0]=pobj; //......................................line 27 dataInterest dobj=new dataInterest(nodeobj[0].pkt[0].type,nodeobj[0].pkt[0].senderid); System.out.println(dobj.type+" "+dobj.id); nodeobj[0].dlist[0]=dobj; System.out.println("datalist has first object with type"+nodeobj[0].dlist[0].type); } } public class node { int x; int y; node nlist[]=new node[5]; dataInterest[] dlist=new dataInterest[5]; packet[] pkt=new packet[1]; public node(){} public node(int a,int b) { x=a; y=b; } } public class Gradient { int id; public Gradient(int a) { id=a; } public Gradient() { } } public class packet { int senderid; int type; public packet(int a,int b) { type=a; senderid=b; } }