Problem:
[sourcecode=’java’]
import java.util.*;
public class Test{
public static void main(String[] args){
ArrayList
x.add(new Student(“Naray”));
x.add(new Student(“Gopal”));
}
}
[/sourcecode]
//in student.java
[sourcecode=’java’]
public class Student {
public Student() {
}
}
[/sourcecode]
Error:
[sourcecode=’java’]
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”));
[/sourcecode]
Solution:
make a only string accepting parameter in student constructor
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.