When is nullexception thrown?

Hi guys,

Please tell me why following code won't run? It keeps saying NullException on the assign( ) method. I don't understand!

class MyTable

{

publicclass Record{

Integer a;

String name;

Record(){

}

void assign(Integer a, String name)

{

this.a=a;

this.name=name;

}

}

Record internal;

static HashMap<Integer,Record> globaltable =new HashMap<Integer,Record>();

MyTable(Integer a, String name)

{

internal.assign(a,name);

globaltable.put(internal.a, internal);

}

void UpdateTable(Integer a, String name)

{

internal.a=a;

internal.name=name;

Set<Map.Entry><Integer,Record>>set=globaltable.entrySet();

for(Map.Entry<Integer,Record>me : set)

{

System.out.print(me.getKey() +": ");

System.out.println(me.getValue());

}

}

}

publicclass Main{

/** Creates a new instance of Main */

public Main(){

}

/**

* @param args the command line arguments

*/

publicstaticvoid main(String[] args){

// TODO code application logic here

Integer x =new Integer(1);

Integer y=new Integer(2);

MyTable a= new MyTable(x, "cat");

MyTable b =new MyTable(y,"dog");

a.UpdateTable(x,"pig");

}

}

Message was edited by:

newbie1124

Message was edited by:

newbie1124

[2771 byte] By [newbie1124a] at [2007-10-3 9:45:34]
# 1
You mean NullPointerException.internal is null. There's no object there, because you didn't do internal = new Record();
jverda at 2007-7-15 5:02:15 > top of Java-index,Java Essentials,New To Java...
# 2
whenever you get a null pointer it means something on that line is null. look for all objects used in that line and figure out which one of them is null
mkoryaka at 2007-7-15 5:02:15 > top of Java-index,Java Essentials,New To Java...