constructor X is undefined
I'm copying some code from another location and I'm confused about something that isn't working:
Code :
return new GeneralClickList<DCNotification>((Vector<DCNotification>) reader.executeReadQuery(query));
GeneralClickList is just an extended List that we use. I took this line from another class that just uses a different object:
Code :
return new GeneralClickList<AnotherObject>((Vector<AnotherObject>) reader.executeReadQuery(query));
On the first one above, I'm getting an error that says the constructor GeneralClickList<DCNotification>((Vector<DCNotific ation>) is undefined. I'm not sure what that means or what to do about it because the constructor for GeneralClickList doesn't reference the other object mentioned above in the second line of code either.
Hopefully this isn't too vague that someone could provide some sort of direction?
Re: constructor X is undefined
What is the exact error? Copy and paste it here.
What is the exact constructor declaration? Copy and paste it here.
What is the exact code you're using to call the constructor? Copy and paste it here.
Re: constructor X is undefined
Error: The constructor GeneralClickList<DCNotification>(Vector<DCNotifica tion>) is undefined
Constructor (I think... there are several):
Code :
public GeneralClickList(Collection<? extends T> c) {
super(c);
}
super is:
Code :
public ArrayList(Collection<? extends E> c) {
size = c.size();
// Allow 10% room for growth
int capacity = (int) Math.min((size*110L)/100, Integer.MAX_VALUE);
elementData = (E[]) c.toArray(new Object[capacity]);
}
The first line in the first post is the call to the constructor.
Re: constructor X is undefined
That's not all of the information we need. How are you calling the constructor? It looks like you're trying to pass in a Vector, which isn't an ArrayList.
Re: constructor X is undefined
I guess I'm not sure what you mean by 'how are you calling the constructor'? Maybe I'm just slow today.
Here are all the constructors for the class:
Code :
public class GeneralClickList<T extends ClickObject> extends ArrayList<T> implements ClickList<T> {
/**
*
*/
private static final long serialVersionUID = 4051311753478592552L;
/**
* Constructs an empty list.
*/
public GeneralClickList() {
super();
}
/**
* Constructs an empty list and then adds the supplied object to it.
*
* @param o the object to add to the list
*/
public GeneralClickList(T o){
super();
this.add(o);
}
/**
* Constructs an empty list and then adds the supplied object to it.
*
* @param array the array of objects to add to the list
*/
public GeneralClickList(T[] array){
super();
for(int i=0; i < array.length; i++){
this.add(array[i]);
}
}
/**
* Constructs a list containing the elements of the specified collection, in
* the order they are returned by the collection's iterator. This list will
* have an initial capacity of 110% of the size of the collection.
*
* @param c the collection whose elements are to be placed into this list
*/
public GeneralClickList(Collection<? extends T> c) {
super(c);
}
/**
* Constructs an empty list with the specified initial capacity.
*
* @param initialCapacity the initial capacity of the list
*/
public GeneralClickList(int initialCapacity) {
super(initialCapacity);
}
Maybe I'm referencing the wrong one?
I'm sorry, Java isn't my strongest language.
Re: constructor X is undefined
That's all the constructors, but how are you calling them? Hint: That's the line you write with the word "new" in it. In your first post, you seem to be passing in a Vector, but I don't see a Constructor that takes a Vector as an argument.
Re: constructor X is undefined
Hence my thought that it's probably this one:
public GeneralClickList(T o){
super();
this.add(o);
}
Using a generic instead of specifying it.
I call it using this: return new GeneralClickList<DCNotification>((Vector<DCNotific ation>) reader.executeReadQuery(query));
which I've said a few times already.
Re: constructor X is undefined
Yeah, that won't work. You're saying that the generic T is DCNotification, so the constructor is expecting an instance of DCNotification, not an instance of a Vector of DCNotification instances.
Re: constructor X is undefined
So then why does the exact same code work for another class?
I guess I have to ask another developer within the company... I hate working in a different office from the rest of them.
Re: constructor X is undefined
Quote:
Originally Posted by
ober0330
So then why does the exact same code work for another class?
I guess I have to ask another developer within the company... I hate working in a different office from the rest of them.
Again, you're talking about code that we can't see, so it's impossible to help you. That SSCCE would go a long way towards making it easier to help you out.