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.
53 Answers
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!
1Hello 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); } For auto importing in Eclipse IDE, you should press Shift+Ctrl+O
Resource Link: