java ArrayList<> 无法解析为类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34190089/
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
ArrayList<> cannot be resolved to a type
提问by BJustice
I am struggling with a homework assignment in my java course. The problem I am having is with constructing instance data. My professor has given us a video to watch and I am following each step, but Eclipse is saying that my ArrayList cannot be resolved to a type.
我正在为我的 Java 课程中的家庭作业而苦苦挣扎。我遇到的问题是构建实例数据。我的教授给了我们一个视频供我们观看,我正在按照每个步骤进行操作,但是 Eclipse 说我的 ArrayList 无法解析为类型。
import.java.util.ArrayList;
public class Campaign {
private String candidateName;
private ArrayList<DonorList> donors;
public Campaign(String name)
{
//TODO Initialize all of the instance data
candidateName = name;
donors = new ArrayList<DonorList>();
}
Any and all help is appreciated.
任何和所有的帮助表示赞赏。
回答by Kyle Gowen
You probably need to add an import statement.
您可能需要添加导入语句。
import java.util.ArrayList;
This goes after your package declaration. This let's the system know what an ArrayList is and what methods it has available.
这在您的包声明之后。这让系统知道 ArrayList 是什么以及它有哪些可用的方法。
Hope that was it!
希望就是这样!
回答by N.Neupane
Hello you have made a lot of mistakes.
你好,你犯了很多错误。
1) There is dot after import. 2) No main method
1) 导入后有点。2) 没有主要方法
and many other.
和许多其他。
Though I have corrected all of them . Hope this finally works.
虽然我已经纠正了所有这些。希望这最终有效。
import java.util.ArrayList;
public class Campaign {
private String candidateName;
private ArrayList<String> donors;
public Campaign(String name, ArrayList<String> a1) {
candidateName = name;
donors = a1;
}
public static void main(String[] args) {
ArrayList <String> aa = new ArrayList <String>();
aa.add("Ram");
aa.add("Sita");
Campaign obj = new Campaign("Nischal",aa);
System.out.println(obj.candidateName + " "+ obj.donors);
}
回答by SkyWalker
For auto importing in Eclipse IDE, you should press Shift+Ctrl+O
要在 Eclipse IDE 中自动导入,您应该按Shift+ Ctrl+O
Resource Link:https://stackoverflow.com/a/11065545/2293534