Doubt in Hashtable while Practicing | Selenium Forum
M
Posted on 21/12/2015
This is my below program

when i am executing this i am getting Null Pointer Exception, can someone explain why ?

My Expectation is to get the zip code of the City3 and print it in the console.

Program:
import java.util.Hashtable;


public class TestHashTable {


public static void main(String[] args) {

Hashtable<String,String> table1 = new Hashtable<String,String>();

table1.put("City1", "LA");
table1.put("City2", "London");
table1.put("City3", "Delhi");

Hashtable<String,String> table2 = new Hashtable<String,String>();

table2.put("City1", "12542");
table2.put("City2", "56455");
table2.put("City3", "3452325");


Hashtable<String,Hashtable<String,String>> table = new Hashtable<String,Hashtable<String,String>>();

table.put("name", table1);

table.put("Zip",table2);

System.out.println(table.get("zip").get("City3"));
}

}

M
Replied on 21/12/2015

Apologies from me

I got the issue, while declaring in table2 i gave the zip as Zip(Capital Z)

while declaring Hashtable inside Hashtable i gave the small z like zip

i corrected it and i got the right result