开发者

Getting NullPointerException from Hashtable while using GObject method

So I try to create 开发者_高级运维a small Zombie-Shooter game. I use a GTurtle class from ACM package (jtf.acm.org). I have additional thread for a GTurtle, which is a GObject. I have a run method with while loop, that is checking if boolean is true, if it is - this.forward() method gets executed.

I tried running game and pressing button, if it is W or D, boolean in GTurtle object gets changed and Thread executes action. Then I get this exception:

java.lang.NullPointerException
         at java.util.Hashtable.put(Hashtable.java:394)
         at acm.util.JTFTools.pause(JTFTools.java)
         at acm.util.Animator.delay(Animator.java)
         at acm.graphics.GTurtle.setLocation(GTurtle.java)
         at acm.graphics.GObject.move(GObject.java)
         at acm.graphics.GTurtle.move(GTurtle.java)
         at acm.graphics.GObject.movePolar(GObject.java)
         at acm.graphics.GTurtle.forward(GTurtle.java)
         at anotherTryJava.Player.run(Player.java:20)
         at java.lang.Thread.run(Thread.java:662)


Judging by the source code for Hashtable.put you either passed key parameter with null or value parameter with null or both null.

From Javadoc.

Throws:

        NullPointerException - if the key or value is null

Note: I do not know the version of the JDK you are using (link below does not have a line 394 matching with your version), although the reasoning remains valid!

http://www.docjar.com/html/api/java/util/Hashtable.java.html

public synchronized V put(K key, V value) {
    if (key != null && value != null) {
        [...]
        return result;
    }
    throw new NullPointerException();
}

Hashtable a = ...;
a.put(null, "s"); // NullPointerException
a.put("s", null); // NullPointerException
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜