import java.util.*;
class MyKey
{
private String name;
private int age;
public MyKey(String name,int age)
{
this.name = name;
this.age = age;
}
public String toString()
{
return new String(name + "," + age);
}
public boolean equals(Object obj)
{
if(name.equals(obj) && age == obj)
{
return true;
}
else
{
return false;
}
}
public int hashCode()
{
return name.hashCode() + age;
}
}
class Thashtable
{
public static void main(String[] args)
{
Hashtable ht = new Hashtable();
ht.put(new MyKey("jimmy",20),new Integer(1));
ht.put(new MyKey("jimm",21),new Integer(2));
ht.put(new MyKey("jim",22),new Integer(3));
Enumeration e = ht.keys();
while(e.hasMoreElements())
{
MyKey key = (MyKey)e.nextElement();
System.out.println(key.toString() + "=");
System.out.println( ht.get(key).toString());
}
}
}
执行Exception in thread "main" java.lang.NullPointerException
at test.Thashtable.main(Thashtable.java:19)
那为大侠帮忙修改一下