Users Pricing

forum

Home Forums Add Object into an ArrayList error using java – MindStick

Add Object into an ArrayList error using java

Anonymous User 2331 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?


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md