Results 1 to 2 of 2
  1. #1
    kvm
    kvm is offline Member
    Join Date
    Dec 2010
    Posts
    1
    Rep Power
    0

    Default 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();
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    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 02:34 AM.

Similar Threads

  1. Constructor Problem
    By Aggy in forum New To Java
    Replies: 9
    Last Post: 01-19-2010, 11:42 PM
  2. [SOLVED] Constructor problem
    By McChill in forum New To Java
    Replies: 3
    Last Post: 03-09-2009, 07:43 PM
  3. Problem with Constructor
    By ToastyBainey in forum New To Java
    Replies: 3
    Last Post: 03-09-2009, 03:36 AM
  4. [SOLVED] Constructor problem
    By sfe23 in forum New To Java
    Replies: 10
    Last Post: 02-21-2009, 09:22 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
  •