Skip to content
August 19, 2008 / Narayan

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

Advertisements

One Comment

Leave a Comment
  1. EJP / Jun 9 2009 4:13 am

    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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: