我正在开发一个项目,我需要从“Itinerary”类型的文件中扫描一个值,但我不知道该怎么做。这是我的代码:
switch (idChar) {
case 'B':
flightNumIn = scanFile.next();
tripDataIn = scanFile.next();
baseFareIn = scanFile.nextDouble();
fareAdjustmentFactorIn = scanFile.nextDouble();
foodBeveragesIn = scanFile.nextDouble();
entertainmentIn = scanFile.nextDouble();
Business bTicket1 = new Business(flightNumIn, tripDataIn,
baseFareIn, fareAdjustmentFactorIn, foodBeveragesIn,
entertainmentIn);
break;
实际错误:
AirTicketProcessor.java:43: error: incompatible types
tripDataIn = scanFile.next();
^
required: Itinerary
found: String
答案 0 :(得分:0)
scanFile.next()返回一个String,而不是一个行程。试试System.out.println(scanFile.next());弄清楚它是什么。
答案 1 :(得分:0)
Scanner.next()
读取String
,但您可以将与“已扫描”类型匹配的构造函数添加到Itinerary
类:
class Itinerary {
public Itinerary(String str, int intValue, ...) {
...
}
}
并像这样创建:
tripDataIn = new Itinerary(scanFile.next(), scanFile.nextInt(), ...);
答案 2 :(得分:0)