-1

I'm very new on Java. I'd appreciate it if your answers considering this situation.

I have question, I want to develop a programme about extend the hashmap to add putchildren method. I wrote something.

My question is :

The task is extending the HashMap to include HashMaps as an object. so, this inner hashMap can also have key value pairs. It will be like tree with depth 2 . When you finish the method data

Key1 = "RUBY" value=HashMap which has -> "key2" = 5248 && "VALUE" = German
Key1 = "PYTHON" value=HashMap which has -> "key2" = 1234 && -> "VALUE" = German

you will implement a putChildrenValue method with 3 parameters, String key, String key, Object Value. It will store the system as described above accordingly.

My code is:

     public class ExtHashMap<K1, K2, V> extends HashMap<K1, HashMap<K2, V>>
     {     
        private static final long serialVersionUID = 1L;

        public ExtHashMap() {       
           super();   
        }

        public void putChildrenValue(K1 key1, K2 key2, V value) { 
            HashMap<K2, V> childMap = get(key2);
            if (childMap == null) { 
             childMap = new HashMap<K2, V>();
             put(key1, childMap);
            }
            childMap.put(key2, value);
         }    
      }

And I run the code, after select Run as Java Application, Eclipse say= "Selection does not contain a main type"

  • 2
    What's your question? – A4L Nov 16 '13 at 12:21
  • i don't see anything wrong with your code. What exactly you are expecting ? – Sage Nov 16 '13 at 12:48
  • I run the code, after select Run as Java Application, Eclipse say= "Selection does not contain a main type" – Burak Teke Nov 16 '13 at 13:04
  • What do you expect to run? – Darkhogg Nov 16 '13 at 13:36
  • It is my project. And the question is this: The task is extending the HashMap to include HashMaps as an object. so, this inner HashMap can also have key value pairs. It will be like tree with depth 2 . When you finish the method data ' **Key1 = "RUBY" value=HashMap which has -> "key2" = 5248 && "VALUE" = German Key1 = "PYTHON" value=HashMap which has -> "key2" = 1234 && -> "VALUE" = German** ' you will implement a putChildrenValue method with 3 parameters, String key, String key, Object Value. It will store the system as described above accordingly – Burak Teke Nov 16 '13 at 13:49
  • Expect I nothing to run? I don't know this :( – Burak Teke Nov 16 '13 at 13:55

1 Answers1

1

Your statement


    HashMap childMap = get(key2);

should be


    HashMap childMap = get(key1);

As you are trying to load the main map.

Dheerendra Kulkarni
  • 2,728
  • 1
  • 16
  • 18