forum

home / developersection / forums / add object into an arraylist error using java

Add Object into an ArrayList error using java

Anonymous User 2197 22-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 !


Message
Can you answer this question?

Answer

1 Answers

Liked By