• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Methods - InputMismatchException  RSS feed

 
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)

 
Marshal
Posts: 60816
190
  • 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: 60816
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from the unnecessary parameter, what is the difference between the two versions?
 
Sheriff
Posts: 12494
206
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!