forum

Home / DeveloperSection / Forums / Add Object into an ArrayList error using java

Add Object into an ArrayList error using java

Anonymous User193622-Oct-2013

I have a problem using add an object of the class Fish to an arraylist call itemList.

My Code: -


public static void main(String[] args) 
{
    ItemList i1 = new ItemList("item#1");
}

Below my class and Constructor: -

public class ItemList 
{
    protected static String name;
    protected static int number;
    protected static List<ItemList> itemList = new ArrayList<ItemList>();
    public ItemList(String in)
    {
        name = in;
        number = 15;
        itemList.add(name, number);
    }
}

How do I add objects to an arraylist properly?


Updated on 22-Oct-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By