473,320 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

error: Exception in thread "main" java.util.InputMismatchException

I dont get it..why is the error: Exception in thread "main" java.util.InputMismatchException
this is my code

Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * @(#)textFileRead.java
  3.  *
  4.  *
  5.  * @author 
  6.  * @version 1.00 2008/10/17
  7.  */
  8.  
  9. import java.io.*;
  10. import java.util.*;    
  11. public class Adamos {
  12.  
  13. static Scanner console = new Scanner(System.in);
  14.  
  15.     public static void main(String[]args) throws FileNotFoundException
  16.         {
  17.  
  18.         Scanner inFile = new Scanner("C:\\Documents and Settings\\elson.KINGJIM\\Desktop\\grade.txt");
  19.  
  20.         int num,count=0;
  21.         double tot=0.0;
  22.         num = inFile.nextInt();
  23.  
  24.         double sum = 0.0;
  25.         double sort[] = new double[num];
  26.         double grade[] = new double[num+1];
  27.  
  28.  
  29.         for(int i=0;i<num;i++)
  30.         {
  31.             int temp = 0;
  32.  
  33.             String frstName =inFile.next();
  34.             String lstName = inFile.next();
  35.             double g1 = inFile.nextDouble();
  36.             grade[temp++] = g1;
  37.             double g2 = inFile.nextDouble();
  38.             grade[temp++] = g2;
  39.             double g3 = inFile.nextDouble();
  40.             grade[temp++] = g3;
  41.             double g4 = inFile.nextDouble();
  42.             grade[temp++] = g4;
  43.             double g5 = inFile.nextDouble();
  44.             grade[temp++] = g5;
  45.  
  46.             tot=g1+g2+g3+g4+g5;
  47.             sum=tot/temp;
  48.  
  49.  
  50.         if(sum>=75)    
  51.         {
  52.         System.out.printf("\n%.2f %s %s Passed",sum,frstName,lstName);
  53.         sort[count++] = sum;
  54.  
  55.             }
  56.         else
  57.         {
  58.         System.out.printf("\n%.2f %s %s Failed",sum,frstName,lstName);
  59.         sort[count++] =sum;
  60.  
  61.         }
  62.         }
  63.         System.out.println("\n\nSorted Average");
  64.         System.out.print("-----------------------------\n");
  65.  
  66.         Arrays.sort(sort);
  67.         for(int i=0;i<sort.length;i++)
  68.         {
  69.         System.out.println(" "+sort[i]); 
  70.  
  71.         }
  72.  
  73.         System.out.println();    
  74.         inFile.close();
  75.     }
  76.  
  77.  
this is whats inside of my grade.txt

5
a b 75.0 76.0 77.0 78.0 79.0
c d 74.0 75.0 77.0 78.0 79.0
e f 70.0 72.0 73.0 74.0 75.0
g h 90.0 89.0 73.0 67.0 89.0
i j 78.0 77.0 75.0 66.0 87.0


this is the error :
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:819)
at java.util.Scanner.next(Scanner.java:1431)
at java.util.Scanner.nextInt(Scanner.java:2040)
at java.util.Scanner.nextInt(Scanner.java:2000)
at Adamos.main(Adamos.java:22)

Process completed.

why is that the error? I don't get it?
Oct 19 '08 #1
1 13686
JosAH
11,448 Expert 8TB
why is that the error? I don't get it?
There must be something else in that input stream that made your scanner barf.
Read what was there instead of that int:

Expand|Select|Wrap|Line Numbers
  1. Scanner inFile= ...;
  2. try {
  3.    // your normal code here
  4. }
  5. catch (Exception e) {
  6.    System.out.println("this made me barf: "+inFile.readLine());
  7. }
  8.  
... and see what happens.

kind regards,

Jos
Oct 19 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Phillip Montgomery | last post by:
Hello all; I'm trying to debug an issue with a java script called, SelectSockets. It appears to be a fairly common one found on the web. I downloaded the SGI Java v1.4.1 installation from SGI's...
1
by: Andy Howells | last post by:
Can anybody help me on this? I am getting the below error but have not got a clue why. The file in my classpath eing used has the class that it says is not defined. Any ideas? I am running java...
12
nomad
by: nomad | last post by:
Hi everyone; My Class has ended and I was not able to solve this problem in time, and I would still like to solve it. I got these error code. Exception in thread "main"...
3
by: Ananthu | last post by:
Hi This is my codings in order to access mysql database from java. Codings: import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement;
4
by: HaifaCarina | last post by:
here's the complete lines of errors.. Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(StringTokenizer.java:332) at...
9
by: tiyaramunna | last post by:
I am trying to configure my system with Java program just to practice on the coding....when i compile a test.java program i am able to see the class file but i cant run the program ... I am getting...
4
by: jmitch89 | last post by:
I don't why I get this error: Exception in thread "main" java.lang.NoClassDefFoundError The statement below works just fine: java -cp...
3
by: ohadr | last post by:
hi, i get Exception in thread "main" java.lang.NullPointerException when i run my application. the exact error is: "Exception in thread "main" java.lang.NullPointerException at...
1
by: onlinegear | last post by:
HI i am writing this for college i know i have loads of combo boxes with nothing in the i havent got that far yet. but every time i run this is comes up with this erro run: Exception in thread...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.