Follwing is my java class TestEntry.java
private void initializemapTest() { eventMap = new TreeMap<String,String>(); //Put some value into eventMap mapTest = new TreeMap<String, String>( new Comparator<String>() { public int compare( String key1, String key2 ) { if( key1 == null ) { if( key2 == null ) { return 0; } else { return 1; } } else { if( key2 == null ) { return -1; } else { return key1.compareTo( key2 ); } } } } ); for( String s : eventMap.keySet() ) { mapTest.put( eventMap.get( s ), s ); //Error at this line } }
According to my knowledge, eventMap does not allow null values, so the eventMap keyset has no null values, if the value of any key in eventMap is null, while I try to put it in mapTest, it shoukd does not throw a null pointer exception, therefore that its corresponding comparator is nullable
But why am I getting this exception
java.lang.NullPointerException at java.util.TreeMap.cmp(TreeMap.java:1911) at java.util.TreeMap.get(TreeMap.java:1835) at kidiho.sa.client.reports.ReportEntry.initializemapTest(TestEntry.java:22)
source share