user1111042
user1111042

Reputation: 1531

HashMap "method put() is undefined for the type HashMap"

I programmed the following into Eclipse but the program keeps giving me the error: The method put(String, String) is undefined for the type HashMap.As far as I know, put() is the correct method to use to input values into a HashMap. Can anyone please help me debug this problem?

import java.util.HashMap; 
public class MapTester 
{ 
public static void main(String[] args) 
{ 
     HashMap <String, String>hm = new HashMap <String, String>(); 
      hm.put("type", "56.09"); 
      hm.put("call", "PHONE"); 
      hm.put("what", "PHONE"); 
      System.out.println(hm.toString());
} 
} 

Thanks.

Upvotes: 2

Views: 8472

Answers (2)

Paul Jowett
Paul Jowett

Reputation: 6581

Check your import statements. Perhaps you are importing a HashMap class from some other library? It should be java.util.HashMap.

Upvotes: 0

Victor Stafusa
Victor Stafusa

Reputation: 14613

Try to build and run the program ignoring what eclipse says about it. Does it run? If not, what the compiler outputs? If in doubt try to build it via command-line.

Eclipse (and Netbeans too) may get confused about some things in the code sometimes due to stale caches, incomplete analysis, classpath problems and a lot of other things.

Upvotes: 1

Related Questions