我尝试以几种不同的方式初始化列表,但仍然出现此错误。 我也尝试了List [0] =(Runner),但随后收到了另一条错误消息。
import java.util.ArrayList;
public class List
{
public static ArrayList<RunnerList>[] List = new ArrayList[10];
public static void main(String [] args){
List.add(new Runner(9.58, "Usain Bolt", "Jamaica", "16 August 2009", "Berlin"));
}
}
//Above is the class with the error. the error is at .add. Below is the constructor for RunnerList
public class RunnerList
{
private double timeRan;
private String runnerName;
private String countryFrom;
private String date;
private String countryRan;
public RunnerList(double tR, String rN, String cF, String d, String cR){
timeRan = tR;
runnerName = rN;
countryFrom = cF;
date = d;
countryRan = cR;
}
}
//below is the class for runner
public class Runner extends RunnerList
{
public Runner(double timeRan, String runnerName, String countryFrom,
String date, String countryRan){
super(timeRan, runnerName, countryFrom, date, countryRan);
}
}