Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArrayList<> cannot be resolved to a type

Tags:

java

typeerror

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.

like image 476
BJustice Avatar asked May 13 '26 22:05

BJustice


2 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!

like image 125
Kyle Gowen Avatar answered May 15 '26 13:05

Kyle Gowen


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


    }
like image 24
N.Neupane Avatar answered May 15 '26 13:05

N.Neupane



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!