Reputation: 115
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.
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.
Upvotes: 9
Views: 65989
Reputation: 11
You shouldn't use a dot after the import keyword, you should write it as
import java.util.ArrayList;
if it doesn't work even after this correction, then it's probably because of a bug in your editor. just close your code editor and reopen it, then the import statement will work fine.
Upvotes: 1
Reputation: 291
Hello you have made a lot of mistakes.
1) There is dot after import. 2) No main method
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);
}
Upvotes: 2
Reputation: 29140
For auto importing in Eclipse IDE, you should press Shift+Ctrl+O
Resource Link: https://stackoverflow.com/a/11065545/2293534
Upvotes: 0
Reputation: 467
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.
Hope that was it!
Upvotes: 15