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

InputMismatchException when using Scanner to to read from a file

I am trying to read from a CSV file using the Scanner but I am getting an InputMismatchException when I try and read the last double and are there is more than one line in my CSV file. I think this is because it is reading \n as part of the double.…
Pyram
  • 57
  • 6
0
votes
2 answers

Solving mismatch exceptions only appearing in one compiler

This is for an online assignment. The goal is to accept two inputs (in this code, the x and y variables) multiple times and then print the largest and smallest value of each variable. Here is the code: import java.io.*; import static…
0
votes
2 answers

I want to catch InputMismatchException but it shows compile time error

I get the following error while compiling: filimon.java:12: error: cannot find symbol }catch(InputMismatchException ime){ ^ symbol: class InputMismatchException location: class filimon 1 error My source…
0
votes
3 answers

Attempting to read double values from a textfile, but a InputMismatchException is thrown

I am trying to make a program that processes "large" text file. The textfile displays 1000 lines, each for one faculty staff member. Each line contains firstname, lastname, rank and salary. Link to the…
Esben86
  • 483
  • 8
  • 21
0
votes
1 answer

InputMismatchException while inputting multiple lines into ArrayList

While putting a .txt file into a list I keep running into a InputMismatchException error. That won't read the "MovieType" or "AlbumTitle". Relevant code has been added. public class MovieManager { public static void main(String[] args) throws…
user4318831
0
votes
0 answers

Pre written input text file throws exception (when input is a double)

I have an assignment for school that is going to be tested using a premade textfile that feeds data into the program. My problem is that this premade text file crashes the program, even though it works without a problem when you type the data in…
0
votes
1 answer

Struggling with try/catch InputMismatch Exception and retrieving data from an array

I'm trying to do the following: Call a method that creates an Array with 100 randomly generated integers. Call a method that prompts the user to enter an index position of the array and returns the value entered. If the value entered by the user…
archer
  • 89
  • 8
0
votes
2 answers

Why there is an InputMismatchException in my code

System.out.print("Input the number of persons: "); Scanner scanner = new Scanner(System.in); int noOfP = scanner.nextInt(); Person[] person = new Person[noOfP]; String name; int age; for(int i = 0; i <…
ZDunker
  • 437
  • 1
  • 6
  • 18
0
votes
0 answers

InputMismatchException when parsing csv file with Scanner

I have been searching for a solution to this but basically whats happening is that I need to make a car database and import the values from a csv file. when I attempt to input the last cell in the csv file, the year, it returns 0 and an input…
0
votes
6 answers

Continue Program Execution after Catching Exception

After catching an exception, how do I continue the execution of a Java program? I made a program that asks a user to enter a number and it will return that number divided by a random number generated. However, if the user enters a letter like 'a',…
0
votes
1 answer

InputMismatchException when reading numbers and text using Scanner

I would like to have the user input a line of text as long as x is not equal to the value of numOfContestans. When I run the code, I get an InputMismatchException. Does anyone have an idea on how to solve this error? try { int numOfContestants =…
kylel95
  • 139
  • 1
  • 6
  • 14
0
votes
4 answers

I can't figure out the "Java InputMismatchException errors" in my code

In my code,I use "\n" as the delimiter, because there may be some 'sapce' in the user's input string. But a exception appeared.I am new to Java and I'm confused.So I'm very grateful to you for helping me out. My code is: import…
0
votes
0 answers

Exception in thread "main" java.util.InputMismatchException "Simple program"

i just started to study and "play" a bit with java. I'm a Computer Engineering student (last year we studied C). However, today i had some problem with "Scanning from File". I work in Eclipse, and after i created a file text "in.txt" containing…
Luca Pierri
  • 53
  • 1
  • 5
0
votes
0 answers

Handling an InputMismatchException

I'm trying to input two ints from a user to generate an array. The first number determines how many elements are in the array, and the second will be the maximum value for a random value generator. I will then add all the positions and find the…
Hart
  • 11
0
votes
0 answers

Why Am I Getting An Error Saying That My Variables Have Not Been Initialized After Importing java.util.InputMismatchException;

So basically the code is a program that solves the necklace program (two number are added and returns only the ones digit. This process is repeated until the original two numbers are returned by the program. I need to error proof it so that strings…