Max
Max

Reputation: 3914

Constructor undefined while the constructor is indeed defined

This line causes error "The constructor Vector(double[], double[]) is undefined":

Vector<trainingSet> set = new Vector<trainingSet>({1.0, 1.0}, {0.0, 0.0});

While the class "trainingSet" has indeed a corresponding constructor:

public class trainingSet {
    public double [] pattern, result;
    public trainingSet(){}
    public trainingSet(double[] Pattern, double[] Result){
        pattern = Pattern;
        result = Result;
    }
}

Any idea?

Upvotes: 0

Views: 263

Answers (5)

Petr Mensik
Petr Mensik

Reputation: 27496

Because you are not initializing trainingSet but the Vector class itself. Vector has only default constructor, constructor with initial size and you can also pass other collections to it. You should do something like

Vector<trainingSet> vector = new Vector<trainingSet>();
double[] result = {1.0, 1.0};
double[] pattern = {0.0, 0.0};
vector.add(new trainingSet(result, pattern));

Also consider using List instead of Vector unless you don't need synchronization. Vector is much more slower collection then a List.

Upvotes: 5

Ivaylo Strandjev
Ivaylo Strandjev

Reputation: 70931

Java's Vector has no constuctor taking a single element of the collection type. Also you are trying to construct the vector by passing two Arrays with doubles, not a trainingSet. Possible fix would be:

Vector<trainingSet> set = new Vector<trainingSet>();
set.add(new trainingSet(new double[]{1.0, 1.0}, new double{0.0, 0.0}));

Upvotes: 2

Darshit Chokshi
Darshit Chokshi

Reputation: 589

You are calling constructor of Vector class which is not exist, try this,

    double[] Pattern={1.0, 1.0};
    double[] Result={0.0, 0.0};

    Vector<trainingSet> set = new Vector<trainingSet>();
    set.add(new trainingSet(Pattern, Result));

Upvotes: 1

Rais Alam
Rais Alam

Reputation: 7016

You are passing parameter to vector constructor and not in the cunstructor of class named trainingSet

Upvotes: 1

TheWhiteRabbit
TheWhiteRabbit

Reputation: 15758

because of your definition Vector<trainingSet>

Vector expects trainingSet type only and not double premitive

you can change it to

Vector<trainingSet> set = 

new Vector<trainingSet>().add(new trainingSet({1.0, 1.0},{0.0,0.0})));

Upvotes: 0

Related Questions