Java “错误:找不到符号HashMap”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21720894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"error: cannot find symbol HashMap"
提问by NoobEditor
Trying to create (or rather learn) a HashMap
in below fashion :
尝试以以下方式创建(或更确切地说学习)a HashMap
:
public class Demo{
public static void main(String args[]){
System.out.println("============Starting Hashmap============");
//hashmap portion
HashMap<String, Integer> myMap = new HashMap<String, Integer>();
System.out.println("============Ending Hashmap============");
}
}
I am using an online complier and have searched a lot, i found that my way of declaration is correct but something else is popping up the error
Below is the error
我正在使用在线编译器并进行了大量搜索,我发现我的声明方式是正确的,但出现了其他错误 错误
如下
Demo.java:8: error: cannot find symbol
HashMap<String, Integer> myMap = new HashMap<String, Integer>();
^
symbol: class HashMap
location: class Demo
Demo.java:8: error: cannot find symbol
HashMap<String, Integer> myMap = new HashMap<String, Integer>();
^
symbol: class HashMap
location: class Demo
2 errors
What i need help in :m just trying to get the basic of creating a hashmap and inserting some key and value in it, but above error stopped me in very first step.....any help in solving this is appreciated!! :)
我需要什么帮助:我只是想获得创建哈希图并在其中插入一些键和值的基础知识,但上述错误使我在第一步中就停止了.....对解决此问题的任何帮助表示赞赏!:)
采纳答案by Abimaran Kugathasan
You need to import the HashMap
into the class
你需要导入HashMap
到类中
import java.util.HashMap;
public class Demo{
public static void main(String args[]){
System.out.println("============Starting Hashmap============");
//hashmap portion
HashMap<String, Integer> myMap = new HashMap<String, Integer>();
System.out.println("============Ending Hashmap============");
}
}
回答by Nambi
you need to import the HashMap to avoid the compile error
您需要导入HashMap以避免编译错误
import java.util.HashMap;