Getting the following error:
101
Exception in thread "main" java.lang.NumberFormatException: For input string: "false"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
For the following code.
public static void main(String[] args) throws FileNotFoundException {
Scanner file = new Scanner(new FileReader("rooms.txt"));
while(file.hasNext()) {
int no = Integer.parseInt(file.nextLine());
System.out.println(no);
String type = file.nextLine();
double price = file.nextDouble();
boolean balcony = Boolean.parseBoolean(file.nextLine());
boolean lounge = Boolean.parseBoolean(file.nextLine());
}
}
}
The file that its reading from is:
101
Single
23.50
false
false
i don't understand whats going wrong. Its loading the "101" from the file then it gets an error. Also i have read through all the similar questions and cant find a solution so don't mark this as a duplicate please.