Results 1 to 3 of 3
  1. #1
    D.Calladine is offline Member
    Join Date
    Nov 2010
    Posts
    11
    Rep Power
    0

    Default Collections, Collection From one class to another

    Hi, im trying to get a collection from one class Department to another Class DeptChooser, so i can put it into an array into a JList and then display it i can get it into a Jlist and display but can't get from Department class into DeptChooser.

    here is my bit of code that i thought would work.

    [code]
    collection.toArray(Department[]);
    JList deptList = new JList(dept);
    deptList.setSelectionMode(ListSelectionModel.SINGL E_SELECTION);
    panel.add(deptList, DeptPanel);
    JScrollPane deptListscroll = new JScrollPane(deptList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    panel.add(deptListscroll, DeptPanel);
    [\code]

    i get a '.class' exspected error

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,474
    Rep Power
    21

    Default

    Where is that error thrown?
    Full error message and stack trace would be good.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,044
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by D.Calladine View Post
    Java Code:
    collection.toArray(Department[]);
    That first line doesn't work; you have to supply an 'exemplar', i.e. an example array for the method (defined in the Collection interface). So that line should be:

    Java Code:
    collection.toArray(new Department[0]);
    What are you going to do with the array returned by the method? As it is now you simply forget about it. As Tolls already wrote: it would be nice to see a bit more context ...

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. collection class in java
    By katturv in forum New To Java
    Replies: 5
    Last Post: 10-24-2010, 07:09 PM
  2. Java Collection class & methods
    By box2box in forum New To Java
    Replies: 2
    Last Post: 05-26-2010, 01:51 AM
  3. Collections
    By Cbani in forum New To Java
    Replies: 3
    Last Post: 02-16-2010, 03:46 PM
  4. know the class coming under the collection api in java
    By javastuden in forum New To Java
    Replies: 1
    Last Post: 11-24-2009, 08:10 AM
  5. Collections Help
    By Dr Gonzo in forum New To Java
    Replies: 0
    Last Post: 12-07-2008, 10:15 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
  •