Questions tagged [inputmismatchexception]

Use this tag on questions regarding input mismatch exceptions that occur when using the `Scanner` object.

The InputMismathException is a Java I/O exception that is thrown when the Scanner object encounters an input which it does not expect. An example would be expecting a double, but receiving a String token instead. This is a runtime exeception that inherits from NoSuchElementException.

258 questions
0
votes
2 answers

error java.util.InputMismatchException

I am new to Java, and am trying to make a program to see if a person has a normal temperature, not too low or too high. I have been getting this error message:(when I'am input a double, not a int) Exception in thread "main"…
kristine
  • 11
  • 1
0
votes
1 answer

InputMismatchException? I still can't figure it out

im trying to make an txt file into sqlite with java. (ID,NAME,CATEGORY,XCOORDINATE,YCOORDINATE,LENGTH,WIDTH,FLOOR) types are orderly INTEGER text text int int int int. (I create ID by AUTOINCREMENT.) An example is like maleToilet room -58 0…
newman
  • 75
  • 1
  • 7
0
votes
3 answers

Reading from file double value using Scanner - InputMismatchException?

I tried read from file double values and using Scanner with this aim. It throws InputMismatchException : "input.txt" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:909) at…
catch23
  • 17,519
  • 42
  • 144
  • 217
-1
votes
1 answer

sc.nextLine() throws InputMismatchException while sc.next() doesn't

In the following code snippet, scanner is throwing InputMismatchException after I input the value for coach and press enter. However if I use coach=sc.next(); , no such exception is thrown. void accept() { System.out.println("Enter name ,…
-1
votes
2 answers

Why Mileage tracker gives InputMismatchException?

Given the MileageTrackerNode class, complete main() in the MileageTrackerLinkedList class to insert nodes into a linked list (using the insertAfter() method). The first user-input value is the number of nodes in the linked list. Use the…
-1
votes
1 answer

How to resolve InputMismatchException in Java

I'm trying to read a .adi file that has a line format of String, Int and Double. For example: Ford,Fusion,2010,85254,12855.58 For the code, I'm required to use a try-catch statement and the method header has to throw the exception. Furthermore, I…
-1
votes
1 answer

Program is giving me a "Exception in thread "main" java.util.InputMismatchException"

This is the code I am using for my program import java.util.*; import java.io.*; import java.util.ArrayList; /** * This program will read the information from the * txt file and will organize and output the information * in a clean and…
-1
votes
1 answer

Summing up times using Duration

For my project, I have to read in data that is given to us in a CSV file and write it out in a certain format. I have it almost done but the problem I am having is that my program is not completely reading through the times that are given. From here…
-1
votes
2 answers

Binary to Decimal calculator InputMismatchException

My goal is to create a simple binary to decimal calculator. I try to go about this by first having the user input a string of the binary value they are trying to calculate and later use the length of this string to run a for loop (as seen in the…
Reza
  • 7
  • 1
-1
votes
2 answers

How do I catch InputMismatchException for doubles a, b, and c in this code?

So I made a calculator that solves the quadratic formula, but I want the program to throw an exception when the variables a, b, or c aren't valid double numbers. However, I can't figure out how to get the variables into the equations that I want…
-1
votes
2 answers

Trying to read a file with various but known input types and getting an InputMismatchException

I am trying to read a file that looks exactly like this C 8230123345450 Simons Jenny R 0 12 C 3873472785863 Cartman Eric N 750 18 C 4834324308675 McCormick Kenny R 0 20 O 1384349045225 Broflovski Kyle …
-1
votes
1 answer

If an invalid input is entered during an iteration of a loop, how do I get the loop to start again at its current iteration

I am new to programming and am working on a Java assignment where a user names a file. The file is then passed to a method for the user to write in test grades, then passed to another method to read and display the test grades with the class…
-1
votes
1 answer

How do I implement a "play again" feature in my java using a while or do-while loop?

I know this same thing has been asked before but I am having a lot of trouble getting this guy to work. EDIT: it now seems to just keep running indefinitely. I no longer get an error but the code will just keep running until I stop it. And now for…
CelineDion
  • 906
  • 5
  • 21
-1
votes
1 answer

Try-catch not working -InputMismatchException

System.out.println("Enter floor: "); int f=x.nextInt(); p.setFloor(f); This code is associated with an object public void setFloor(int floor){ try{ this.floor = floor ; }catch (InputMismatchException e){ …
DCodes
  • 789
  • 1
  • 11
  • 27
-1
votes
1 answer

Why does this program result in an InputMismatchException?

private static int[] loadMarks(String fileName) throws IOException { int[] marks = new int[94]; /* complete */ Scanner input = new Scanner(fileName); for(int i=0;i<94;i++) { marks[i]=input.nextInt(); } return…