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

    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.

    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);

    i get a '.class' exspected error

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power


    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
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    Quote Originally Posted by D.Calladine View Post
    Java Code:
    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,

    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