File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Null pointer exception on using hashtable get() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Null pointer exception on using hashtable get()" Watch "Null pointer exception on using hashtable get()" New topic

Null pointer exception on using hashtable get()

Bravi kumar

Joined: May 03, 2012
Posts: 3

I am facing the null pointer exception since many days.

Could anybody please help me how to fix the above null pointer exception ?

I am copying the error trace from eclipse console window.

Caused by: java.lang.NullPointerException
at java.util.Hashtable.get(

Thanks for helping.


Tony Docherty

Joined: Aug 07, 2007
Posts: 2839
Not sure why this is posted in Performance it should probably be in the beginners section. How does one get it moved?

You are probably getting an NPE because you are passing a null value to the get method. Hashtable does not allow null keys.
BTW why are you using Hashtable, most people use HashMap instead these days.
Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 187

Obviously, you have to debug and find out where exactly that get method is getting null from!

The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory |
R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 375

Hello Bravi,

You need to post some code here to get valuable input from others..
We cannot just see a random error and tell where it went wrong without even concerning about where it came from??
See PostRealCode <- click and TellTheDetails <- click
And before you post any code, see UseCodeTags <- click
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46437
Why are you using Hashtable?

You realise Hashtable does not allow null values for keys or values, and will probably throw that Exception if you try to use pass a null parameter to any of its methods. You can verify that by reading the documentation for Hashtable and its get method.
I agree. Here's the link:
subject: Null pointer exception on using hashtable get()
It's not a secret anymore!