Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem with nextDouble when reading txt files

807601Jan 2 2008 — edited Jan 2 2008
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 30 2008
Added on Jan 2 2008
14 comments
2,940 views