这是我的代码:
public class FlightMap implements FlightMapInterface {
LinkedList<City> cityList = new LinkedList<City>();
LinkedList<City> nextCity = new LinkedList<City>();
/**
* Creates an empty FlightMap
*/
public FlightMap() {
}
public void loadFlightMap(String cityFileName, String flightFileName)
throws FileNotFoundException {
File cityList = new File(cityFileName);
File flightsTo = new File (flightFileName);
Scanner theCityFile = null;
Scanner theFlightFile = null;
Scanner theRequestFile = null;
ArrayList<String> cityStringList = new ArrayList<String>();
int counter = 0;
try {
theCityFile = new Scanner (cityList);
theFlightFile = new Scanner (flightsTo);
}
catch (FileNotFoundException e) {
System.out.println("No such file exists.");
}
while (theFlightFile.hasNextLine()) {
cityStringList.add((theFlightFile.nextLine()).replaceAll("\t", ""));
}
while (theCityFile.hasNextLine()) {
LinkedList<City> tempList = new LinkedList<City>();
String tempCity = theCityFile.nextLine();
nextCity.add(tempList); // ERROR
nextCity.get(counter).add(new City(tempCity)); // ERROR
for (int x = 0; x < cityStringList.size(); x++) {
if (cityStringList.get(x).charAt(0) == tempCity.charAt(0)) {
insertAdjacent(nextCity.get(counter).getFirst(), // ERROR
new City(cityStringList.get(x)).charAt(1) + ""); // ERROR
}
}
cityList.add(new City(tempCity)); // ERROR
counter++;
}
}
对于我的错误:
- 线程“main”java.lang.Error 中的异常:未解决的编译问题:
- LinkedList 类型中的方法 add(City) 不适用于参数 (LinkedList)
- 未定义 City 类型的 add(City) 方法
- 未定义 City 类型的 getFirst() 方法
- charAt(int) 方法未为 City 类型定义