Problem at Constructor’s Parameter

Problem:

import java.util.*;
public class Test{
public static void main(String[] args){
ArrayList<Student> x = new ArrayList<Student>();
x.add(new Student("Naray"));
x.add(new Student("Gopal"));

}

}

//in student.java

public class Student {

public Student() {
}

}

Error:

Test.java . 16 cannot find symbol
symbol: constructor Student(java.lang.String)
location: class Student
x.add(new Student("Naray")); Test.java . 17 cannot find symbol
symbol: constructor Student(java.lang.String)
location: class Student
x.add(new Student("Gopal"));

Solution:

make a only string accepting parameter in student constructor

One Response

  1. That’s not an ArrayList problem, it’s a problem with your Student class, and you have mis-stated the solution. It is to declare a constructor that takes a single String argument, or better still to only make use of the constructors that do exist instead of inventing one and wondering why you get compilation errors.

Leave a Reply