Cryptic compiler error

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Cryptic compiler error

  1. #1
    Join Date
    Oct 2002

    Cryptic compiler error

    Hi all,

    I have a class I am implementing called a Deque. Deque has a method called ensureCapacity that increases the size of the array holding the deque automatically.

    Here is the implementation of ensureCapacity:

    public Deque ensureCapacity(Deque elementData){

    Deque newElementData = newDeque (elementData.length*2);

    int indexOffSet =( (newElementData.length()) - elementData.size() )/2;

    System.arraycopy(elementData, front, newElementData, indexOffSet, elementData.size());

    front = indexOffSet;

    back = indexOffSet + elementData.size();

    }//End of ensureCapacity

    The call I use to the method is this:

    elementData = ensureCapacity(elementData);

    I would expect the method to return a new Deque with the old Deque inserted into the middle of the new array. However the compiler complains and says:

    ensureCapacity(Deque) in Deque cannot be applied to (java.lang.Object[])

    elementData = ensureCapacity(elementData);

    What have I done wrong here? Thanks for any help.
    "I hope that one day I will be able to answer someone elses questions!"

  2. #2
    Join Date
    Mar 2003
    Well, I don't know too much about increasing sizes of arrays and things like that, but the error message you got means that you cannot use that class to increase the size of an array for an object. Maybe if you try to pass the Deque instead as an array of integers it might work. What exactly does the Deque object hold? Maybe there's a better way of doing it... Hope this helps!
    - Master Of Souls
    "Weeks of coding can save hours of planning."

  3. #3
    Join Date
    Mar 2003
    Check what type of variable elementData is. From the compile error I'm guessing it's an array. This will not work as the method expects a single reference.

  4. #4
    Join Date
    Mar 2003
    if you want to change the size of an array, you might wanna try using the Vector class. it's an unlimited array.
    you can read about it somewhere in the beginner tutorials here in the site which is called "java by example"
    I wonder how poisoned Java tastes like....

  5. #5
    Join Date
    Mar 2003

    Thumbs up

    ...or java.util.ArrayList. It's more efficient than Vector (it's all to do with synchronzing in multi-threaded code).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center