我正在尝试创建一个允许雇用自行车的系统。我已经设法让系统的其他部分工作,但我遇到的麻烦是试图让系统的招聘部分到位。这是我的第一个主要编程项目,并希望看到系统完全运行。所有帮助将不胜感激。
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1540)
at bikehire.textdao.TextBikeDAO.loadBikes(TextBikeDAO.java:46)
at bikehire.BikeHireIncrement1.loadCars(BikeHireIncrement1.java:122)
at bikehire.BikeHireIncrement1.main(BikeHireIncrement1.java:35)
这是我在尝试运行自行车租赁功能的主要课程时遇到的错误。下面是TextBikeDAO和BikeHireIncrement1。
@Override
public List<Bike> loadBikes(Path path) {
List<Bike> bikes = new ArrayList<>();
try (Scanner s = new Scanner (new BufferedReader(new FileReader(path.toString())))) {
s.useDelimiter(Character.toString(DELIMITER));
Bike b;
int bikeId;
String bikeBrand, bikeType;
float dailyCost = 0;
while (s.hasNext()) {
if (s.hasNextInt()) {
bikeId = s.nextInt();
}
else {
bikeId = 0;
}
bikeBrand = s.next();
bikeType = s.nextLine();
b = new Bike(bikeId, bikeBrand, bikeType, dailyCost);
bikes.add(b);
}
s.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(TextBikeDAO.class.getName()).log(Level.SEVERE, null, ex);
}
return bikes;
}
\&#39; s.nextline();&#39;是为错误突出显示的代码。
其他错误是我的主要类BikeHireIncrement1。
public static void main(String[] args) {
Scanner userInput = new Scanner (System.in);
char choice;
List<Customer> customers=loadCustomers();
List<Bike> bikes=loadBikes();
List bikes = loadBikes();被认定为错误。
public static List<Bike> loadBikes() {
List<Bike> bikess;
Path path=Paths.get("bikes.txt");
TextDAOFactory daoFactory = (TextDAOFactory) DAOFactory.getDAOFactory(1);
TextBikeDAO dao = (TextBikeDAO) daoFactory.getBikeDAO();
bikes = dao.loadbikes(path);
return bikes;
}
和bikes = dao.loadbikes(path);也正在被强调。
同样,任何帮助都会非常感激,因为这是我第一次尝试完成编程应用程序。 关于我做错了什么,我真的很遗憾,因为一切都编译没有任何错误。
谢谢!
编辑***我已确保s.nextline为另一个值,但似乎仍然得到相同的错误。