I’m having a problem trying to copy a hashtable then adding some values. I have two different hashtables(for debug purposes). The first hashtable I declare and set it equal to another hashtable.
Hashtable model1 = model;
The second hashtable is declared and initialized with the original hashtable which should copy every single element and key into the new Hashtable.
Hashtable model2 = new Hashtable(model);
However, when I try to get a element back from model2, it always throws a NullPointerException. However, the first instance(model1) doesn’t throw anything(though it doesn’t give me the results I want because it adds a reference to the model instance). Any help or advice would e appreciated!! 🙂
If the value you are retrieving is null, you are getting a null
Booleanobject but then the JVM is trying to auto-unbox it to a primitive, but since the value is null, you get a null pointer exception. You should verify that the value you are trying to get is in fact not null. Try it without the auto-unboxing behavior and see what happens.From the JavaDoc for Hashtable: Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.