0

I am trying to modify an ArrayList in a map, but it keeps giving me the "Symbol not found error"

Here is the code:

Map inventories = new TreeMap<String, ArrayList<Item>>();
inventories.put("itms_eqped", new ArrayList<Item>(6));
System.out.println(inventories.get("itms_eqped").get(0));

Here is the error

./Main.java:29: error: cannot find symbol
System.out.println(inventories.get("itms_eqped").get(0));
                                                ^
symbol:   method get(int)
location: class Object

I've also tried adding stuff to the arrayList and I'm getting the same error: "Cannot find symbol".

1 Answers1

1

You have to declare type of your key and value for Java to know which type it should use. Otherwise, java will consider your key and value as type Object.

Map<String, ArrayList<Item>> inventories = new TreeMap<>();
Ananta
  • 553
  • 4
  • 9