Results 1 to 2 of 2
Thread: Problem with constructor
- 12-11-2010, 01:12 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 1
- Rep Power
- 0
Problem with constructor
The compiler errors I'm getting:
cannot find symbol constructor ContentPanel(java.util.ArrayList<Order>)
cannot find symbol constructor ContentPanel(java.util.ArrayList<Customer>)
cannot find symbol constructor ContentPanel(java.util.ArrayList<Item>)
However, in the constructor header for ContentPanel, I have a parameter for an array list of objects implementing the ListableItem interface. The classes Order, Customer, and Item all implement the ListableItem interface.
Here's my code. I've cut out the unnecessary bits. The lines where the errors happened are in bold.
Java Code:public class FrontEnd extends JFrame implements ActionListener { private ArrayList<Customer> customerArray; private ArrayList<Item> itemArray; private ArrayList<Order> orderArray; public FrontEnd(){ } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("Order List") || e.getActionCommand().equals("Customer List") || e.getActionCommand().equals("Item List")) { addContentPanel(e.getActionCommand()); } } public void addContentPanel(String arg) { mainPanel.remove(contentPanel); if (arg.equals("Order List")){ [B]contentPanel = new ContentPanel(orderArray);[/B] mainPanel.add(contentPanel); } else if (arg.equals("Customer List")){ [B]contentPanel = new ContentPanel(customerArray);[/B] mainPanel.add(contentPanel); } else if (arg.equals("Item List")){ [B]contentPanel = new ContentPanel(itemArray);[/B] mainPanel.add(contentPanel); } } }Java Code:public class ContentPanel extends JPanel { public ContentPanel(ArrayList<ListableItem> listItems){ } }Java Code:public interface ListableItem { public String getTitle(); }
- 12-11-2010, 01:27 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
You don't actually say what Customer, Item and Order are (and what they implement).
But try and compile this:
Java Code:import java.util.ArrayList; import java.util.List; interface Foo {} class Bar implements Foo {} public class Main { public static void main(String[] args) { func(new ArrayList<Bar>()); } static void func(List<Foo> arg) {} }
A list of Bar is not a (type of) list of Foo. Read about the butterflies, lions and their animal cages in the Subtyping section of Oracle's Generics Tutorial.
[Edit] And read the next section on wildcards.Last edited by pbrockway2; 12-11-2010 at 01:34 AM.
Similar Threads
-
Constructor Problem
By Aggy in forum New To JavaReplies: 9Last Post: 01-19-2010, 10:42 PM -
[SOLVED] Constructor problem
By McChill in forum New To JavaReplies: 3Last Post: 03-09-2009, 06:43 PM -
Problem with Constructor
By ToastyBainey in forum New To JavaReplies: 3Last Post: 03-09-2009, 02:36 AM -
[SOLVED] Constructor problem
By sfe23 in forum New To JavaReplies: 10Last Post: 02-21-2009, 08:22 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks