• Post Reply Bookmark Topic Watch Topic
  • New Topic

Methods - InputMismatchException  RSS feed

 
Damien Sky
Greenhorn
Posts: 14
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to write a program to calculate my weight on different planets and to do that, I have to read in the surface gravity of all the planets from a file using a separate method from main



I get this message in the while loop when I try to run the program:

java.util.InputMismatchException;
null (in java.util.Scanner)
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many things are you trying to read? How many times does the loop run?
 
Damien Sky
Greenhorn
Posts: 14
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind. I realized I could do this and it stopped giving me an error:

 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from the unnecessary parameter, what is the difference between the two versions?
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your program will throw an ArrayIndexOutOfBoundsException if there are more than eight numbers in your file.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!