哈希地图"method put() is undefined for the type HashMap"



我将以下内容编程到Eclipse中,但程序一直给我错误:The method put(String, String) is undefined for the type HashMap.据我所知,put()是用于将值输入HashMap的正确方法。有人能帮我调试这个问题吗?

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());
} 
} 

谢谢。

尝试构建并运行程序,忽略eclipse对它的描述。它能运行吗?如果不是,编译器输出什么?如果有疑问,请尝试通过命令行构建它。

Eclipse(以及Netbeans)有时可能会因为过时的缓存、不完整的分析、类路径问题和许多其他事情而对代码中的某些事情感到困惑。

检查您的import语句。也许您正在从其他库导入HashMap类?应该是java.util.HashMap

相关内容

最新更新