I am currently learning about arrays and the weblesson from my class is teaching me about the ArrayList class. I tried to make my own array to try it out, but when I followed the format the weblesson showed me, I get a compiler error that reads: "no suitable method found for add(java.lang.String)". While highlighting the ".add".
import java.util.ArrayList;
public class String
{
ArrayList <String> myArrayList;
public void arrayTest()
{
ArrayList <String> names = new ArrayList <String> ();
names.add("John");
names.add("Smith");
names.add("Matt");
System.out.println(myArrayList.get(1));
}
}
ArrayListand stored it innamesreference, then you filled it with data, but in next step you are trying to read data from uninitializedmyArrayListreference.