PDA

View Full Version : problem with nextDouble when reading txt files



Dennis_Gull
01-02-2008, 09:36 PM
Hello, im very new to java and im trying to read a double number from a text file but I get an error if i dont write int values, for example:

my txt file:


John Smith
32.5

part of my Java code:


out.println(myScanner.nextLine());
out.println(myScanner.nextDouble());

(myScanner read my text file)

but I get this error:


Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextDouble(Scanner.java:2387)
at TeamFrame.<init>(TeamFrame.java:15)
at Baseball.main(Baseball.java:14)


Im following the Java for dummies book and according to the book this should work.