Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: constructor X is undefined

  1. #1
    Member
    Join Date
    Feb 2011
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default constructor X is undefined

    I'm copying some code from another location and I'm confused about something that isn't working:
    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:

    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?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,290
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Feb 2011
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: constructor X is undefined

    Error: The constructor GeneralClickList<DCNotification>(Vector<DCNotifica tion>) is undefined

    Constructor (I think... there are several):
    public GeneralClickList(Collection<? extends T> c) {
            super(c);
        }

    super is:
    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.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,290
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member
    Join Date
    Feb 2011
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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:
    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.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,290
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Member
    Join Date
    Feb 2011
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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.

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,290
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    Member
    Join Date
    Feb 2011
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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.

  10. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,290
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: constructor X is undefined

    Quote Originally Posted by ober0330 View Post
    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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. [SOLVED] Error in constructor
    By hello_world in forum What's Wrong With My Code?
    Replies: 9
    Last Post: August 14th, 2011, 07:46 PM
  2. Copy Constructor
    By Rhyssa6 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 23rd, 2011, 10:43 PM
  3. Undefined Array Problem
    By oakheart in forum Other Programming Languages
    Replies: 2
    Last Post: April 18th, 2011, 09:19 AM
  4. [SOLVED] Cannot Find Constructor
    By jrookie in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 8th, 2010, 01:54 PM
  5. he operator / is undefined for the argument type(s) String, int
    By mtbr00x in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: September 8th, 2009, 08:34 PM