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

