Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes I think I'm stuck!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I think I Watch "I think I New topic

I think I'm stuck!!

mike statham

Joined: Feb 24, 2012
Posts: 23
Program will not print anything, and only error is
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(
at java.util.Scanner.nextInt(
at java.util.Scanner.nextInt(
at StudentGrades.getAverage(
at StudentGrades.main(

Matthew Brown

Joined: Apr 06, 2010
Posts: 4544

If you follow the link the forum software has put in for java.util.InputMismatchException, it will take you to the documentation. Which says "Thrown by a Scanner to indicate that the token retrieved does not match the pattern for the expected type, or that the token is out of range for the expected type."

You're getting it thrown on line 37, which is testScore[num] = inFile.nextInt(); This means that the next thing that's being read by the Scanner isn't an integer. So, what is it? It's all to do with what's in your input file. What is it trying to read at this point?
I agree. Here's the link:
subject: I think I'm stuck!!
It's not a secret anymore!