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
1 answer

Java, scanner, input mismatch exception

this part of code should load name of restoraunt, then menu name, then meal name and price but when i run it, it takes in all the names and then when it finally comes to price, i input for example 7.2 and get input mismatch exception String…
user2627736
  • 281
  • 1
  • 4
  • 13
0
votes
3 answers

Exception in java "java.util.InputMismatchException"

So, I am working on a code for class and can't figure what is wrong. The code compiles and when I enter the file I'm searching for, I get this message: Enter the name of the file: FanData.txt Exception in thread "main"…
user3562806
  • 219
  • 1
  • 2
  • 6
0
votes
2 answers

Code working awhile ago then "java.util.InputMismatchException"

Take it easy, I'm self-taught and am pretty new to all this. So I was trying to write an Address Book. everything was working fine, no errors, no exceptions. Saved the project, switched of my laptop, went for lunch. Came back, tried to run the code,…
AidenH
  • 1
  • 1
0
votes
1 answer

"Customizing" InputMismatchExceptions

I want the user to input a string of letters representing grades (for example, ABEDCBA, etc.). Is there a way to "customize" an InputMismatchException so that when a letter after E is entered, it throws that exception? Or should this case be handled…
srsarkar7
  • 155
  • 5
  • 19
0
votes
2 answers

InputMismatchException when using an input Scanner

I am writing a program that reads through a file of various types of data. I am trying pass in the data from the file, to various arrays that I have created. Sample portion from file (double spaced for line breaks. White spaces between categories…
Rivers31334
  • 644
  • 1
  • 12
  • 30
0
votes
2 answers

Java - How to replace "java.util.InputMismatchException" error with something else

How do I make it so a "java.util.InputMismatchException" doesnt show? For example: import java.util.Scanner; class Test { public static void main(String args[]){ Scanner input = new Scanner(System.in); int number; …
hhaslam11
  • 191
  • 2
  • 7
  • 24
0
votes
2 answers

Input mismatch when reading from a file

I have a file with data organized like so: Hyundai Santa Fe 2005 16999 8 Mercury Mountaineer AWD 2004 17999 7.5 Mercury Grand Marquis 2006 19999 12.5 The first line being car name, next line being year, price, and discount amount. I'm trying to…
nullByteMe
  • 6,141
  • 13
  • 62
  • 99
0
votes
1 answer

Exception in thread “main” java.util.InputMismatchException "Temperature program"

Can someone help with this? I can get it to run, but after the output message "What is the outside Temperature:" "Number here" Type (C) for Celsius or (F) for Fahrenheit: Once I type in C or F it gives me this error message Exception in thread…
0
votes
1 answer

Java file input and manipulation of data to file output

Hey so aim working on a program that reads exercise data from a text file and prints a summary of that data to another text file. The input file consists of several records sample input from the txt file looks like this: 1) Joe Schmoe 76.5 20…
0
votes
3 answers

InputMismatchException in LOOP

I tried to find a solution for my problem, but couldn't find one that worked in practice. So please, if YOU'RE NOT SURE you know what the solution is, don't answer. I really need concrete help. The problem is that when I run my simple code - you can…
0
votes
3 answers

InputMismatchException for 2D array

Check the comments below. I was using... Scanner input = new Scanner("rates.txt"); Should be using... Scanner input = new Scanner(new File("rates.txt"));
0
votes
1 answer

How to read ints and doubles in a .txt, while skipping the text?

I'm very new to java - I've got a text file with data about employee wages and hours worked per week. I need to figure out how I can read through the data whilst skipping the text headings above each section, and then have the data ready so that I…
DinosaurHunter
  • 652
  • 2
  • 9
  • 23
0
votes
1 answer

Handling exception and getting message dialog to show

I'm trying to get the user to input an integer into the textfield. The try catch block should handle the exception when the user enters a non-integer. A message dialog should appear, telling the user that they should input something else but I can't…
0
votes
4 answers

Scanner for long integer, Exception in thread "main" java.util.InputMismatchException

I am at the last step to finalize my program, however whenever I enter my integer (long) I get a input mismatch: Compiler message: "Exception in thread "main" java.util.InputMismatchException: For input string: "4388576018402626" at…
0
votes
2 answers

Java: Getting the Value of the User Input that Threw an Exception

I'm trying to catch an InputMismatchException with the Scanner expecting a double, and if the input is equal to "c" or "q" I want to do run some specific code in the catch block. I'm wondering if there's a way to get the value of the user input…