Results 1 to 7 of 7
  1. #1
    mhouldridge is offline Member
    Join Date
    Sep 2009
    Posts
    4
    Rep Power
    0

    Default Strange, 'Cannot find symbol' error

    Java Experts,

    I have added a JList to the GUI of my application. When running the project I received the error, 'Cannot find symbol' with, 'setListData' underlined. here's the code:

    private void displayGroup()
    {
    Collection<Team> teams = football.getTeams();
    teamList4.setListData(teams);
    teamList4.setSelectedIndex(0);
    }

    I have followed an example from a textbook, so I'm curious what error has been made here.

    Please help.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Look up in the API what JList#setListData takes for its parameter. According to the API that I've just looked at, there are two possible choices here, but Collection is not one of them.

  3. #3
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    7

    Default

    setListData intake array or vector, not collection, vector implements collection, but collection is not vector

  4. #4
    mhouldridge is offline Member
    Join Date
    Sep 2009
    Posts
    4
    Rep Power
    0

    Default

    Hi,

    I have looked at the autocomplete for the JList which shows:

    setListData(Object[])
    setListData(Vector[])

    I thought Object was a generic type which could accept any variable type?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    That's not Object, that says Object[], and that's a big difference. It will accept an array of any object, but Collection<...> is not an array.

  6. #6
    mhouldridge is offline Member
    Join Date
    Sep 2009
    Posts
    4
    Rep Power
    0

    Default

    Thanks, just realised this.

    Could you advise how I can convert my Collection to an object array.

  7. #7
    mhouldridge is offline Member
    Join Date
    Sep 2009
    Posts
    4
    Rep Power
    0

Similar Threads

  1. Replies: 9
    Last Post: 10-18-2008, 09:26 PM
  2. 'Cannot find symbol' error
    By minihazard10 in forum New To Java
    Replies: 6
    Last Post: 10-10-2008, 05:05 AM
  3. cannot find symbol class error
    By po0oker in forum New To Java
    Replies: 5
    Last Post: 10-31-2007, 03:52 PM
  4. Error: cannot find symbol
    By silvia in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:39 AM
  5. Error: cannot find symbol
    By cachi in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 09:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •