Reputation: 368
I am trying to create a 2D array of objects but getting this error:
array required, but List<List<TransitionObject>> found
----
This is my TransitionObject Class:
public class TransitionObject {
public char character;
public int state;
TransitionObject(char character, int state)
{
this.character=character;
this.state=state;
}
}
and this is my main class code:
List<List<TransitionObject>> liist = new ArrayList<List<TransitionObject>>();
liist.add(new ArrayList<TransitionObject>());
liist[0].add(new TransitionObject('a',1));
liist[0].add(new TransitionObject('b',3));
I am getting this error when I try to add an object to my list. Solution with a short example would be nice. Thanks !
Upvotes: 5
Views: 1105
Reputation: 12523
liist[0].add(new TransitionObject('a',1));
is wrong. liist
is no array
.
if you need the first element from a List
use get()
liist.get(0).add(new TransitionObject('a',1));
Upvotes: 2