263 questions
-1
votes
0
answers
37
views
How to handle non-numeric input when using scanner.nextInt() in Java [duplicate]
I’m learning Java and testing basic input handling.
I wrote the following simple program:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner ...
-2
votes
1
answer
90
views
Convert string list into List<String> in java using json deserialization
Trying to convert a json string (like below) into a List<String>
"{
"stringField": "abc",
"listField": "[\"item1\", \"item2\", \"...
0
votes
0
answers
75
views
Java Scanner nextBigDecimal throwing InputMismatchException exception
I wrote some simple Java code to take input from the console (using Eclipse 2016 IDE) to assist with iterating through a text file and outputting a file in SWIFT MT940 statement structure. For the ...
-2
votes
1
answer
62
views
Java InputMismatchException is thrown for certain input in my program idk why its being thrown [duplicate]
Code:
import java.util.*;
public class InputInJava {
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
String name = sc.next();
String fName = ...
0
votes
0
answers
31
views
how can i limit the user to a certain input [duplicate]
Hi I'm trying to learn java
This a simple program that stores a patient's blood details, well in any case how can i keep the program accurate by means of returning an error message if the input was ...
1
vote
0
answers
17
views
Inputmismatchexception with reading from txt file
I have a program that is supposed to read from a txt file, compute the necessary functions, then print to another file. I can't seem to find the inputmismatchexception. Any help would be greatly ...
0
votes
0
answers
39
views
I keep having InputMismatchException error every time I type the name of the person in the Scanner?
what is the problem with my code and why do I have the InputMismatchException error every time I type the name in the console ?
Scanner sc = new Scanner(System.in);
System.out.println("...
0
votes
1
answer
79
views
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 ...
0
votes
1
answer
33
views
How to store values in custom object array using Scanner in Java?
I was given an exam, where I had to create a class and after that, I had to write two functions in which the input parameter is an object Array and took the values from user input. Below is the code ...
1
vote
3
answers
91
views
Application throws InputMismatchException when string is assigned to double
I am writing a program where I need to check if a string (name) contains any whitespaces or not.
Here's part of my program :
public static void main()
{
Scanner sc = new Scanner(System....
0
votes
1
answer
95
views
How do I message an end user that they are entering the wrong input and/or format without getting an Exception/Crash?
"Eclipse IDE for Java Developers (includes Incubating components) Version: 2023-03 (4.27.0)"
Intro to Programming using Java Section 3.5.3
Sorry for the very long post. This is my first post ...
0
votes
1
answer
2k
views
SQL Error mismatched input 'sql_query' expecting {EOF} when using Create Table in Pyspark
I'm reading sql code from a zip file of text files, saving the query as a variable sql_query, and passing the variable into a spark dataframe like spark.sql('sql_query'). The query text I parse out ...
0
votes
0
answers
50
views
InputMismatchException when attempting to run program again in do while loop
Having successfully created a policy holder and writing the information to csv I try to run the program again using a do while loop but receive an inputmismatchexception after typing surname.
Can ...
0
votes
1
answer
45
views
Why can't I put a double value for b here?
I tried something like this but
public static void main(String[] args){
Scanner Inp = new Scanner(System.in);
System.out.println("****Bread Store Inventory****");
System.out....
0
votes
2
answers
303
views
Try/Catch loop issues for paint calculation
The goal is to make code that can handle exceptions and keep going. I made a try/catch for typing string instead of numbers, but when I test it, it prints the catch output but then has these errors :
...
0
votes
2
answers
692
views
How to take input in java where array length is not defined?
My input is in this format:
1 2 3 4 5 6
Alice
The array length is not known.
I coded it this way:
import java.util.*;
public class Main
{
public static void main(String[] args) {
List<...
-1
votes
2
answers
4k
views
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 ...
0
votes
1
answer
106
views
My while loop meant to catch an exception and ask for a new input is repeating infinitly, and I'm not sure why [duplicate]
I'm a very beginner programmer, in my first year of college. Currently, I'm trying to write some Java code to have the user insert a pin number using a scanner, asking for a new input if the pin ...
0
votes
0
answers
19
views
Input Mismatch exception Java [duplicate]
I am getting the input mismatch exception error on my code.
I am getting error at the Engine displacement line.
Scanner scanner = new Scanner(System.in);
Car[] arr;
System.out.println(&...
0
votes
1
answer
75
views
How do I resolve an inputmismatchexception from user whilst using the java try with resources feature
I've found that if I use the try with resources feature java provides which will automatically close of resources, I then can't use a boolean flag (or recursion) to resolve an InputMismatchException ...
0
votes
2
answers
31
views
Difference between two codes and InputMismatchException
I am a newbie with java and the class scanners.
I have two Codes and I dont get the point why one of them throws a InputMismatchException.
I look forward to the answers.
Here both codes:
1st one with ...
0
votes
2
answers
209
views
input miss match control in java with try catch
i wrote this code to control input so user cannot enter anything except integers
but problem is that: when an Exception occures, the message in Exception block is continousely printed and never ends, ...
0
votes
2
answers
388
views
I am doing my homework and I stuck in one question. I am new to java. can you help me? [duplicate]
The question is:
Create a class person with attribute name, age and gender. Create an array of the person to hold 10 person instances. Display the information stored on the person instance in the ...
0
votes
2
answers
41
views
InputMismatchException Java first scanner works second does not
This code is working for the first scanner to accept ints but the second scanner throws a mismatch error. I cannot seem to find why it is doing this. Can anyone help me out?
I have tried everything ...
0
votes
1
answer
34
views
InputMismatchException occurred when inputing String and Double values
Here is my problem I've been struggling with:
I want the input to be in this form:
1
So I wrote the code like this. Unfortunately, it either gives me an InputMismatchException at line 6 or cannot ...
0
votes
1
answer
905
views
Is there a way to only get the value from an input method to another method without repeating the whole process again in java?
I really want to know if there is a way to only get the value from the method to an another method. Because in the main method the first method is already call out while the the second needed the ...
2
votes
2
answers
398
views
Scanner#nextDouble fails to parse 5.2 (InputMismatchException) [duplicate]
Problem
I was messing around with Java today, and bumped into something that I can't fix by myself. I'm trying to get a double value from scanner but always get this error:
Exception in thread "...
0
votes
1
answer
679
views
How to avoid InputMismatchException in java while taking input in int,char and int
I am new to Java and I want to solve a simple problem in java.
In input I need to take an integer a and then a character c and then another integer b And print the output if the character is '+' then ...
0
votes
1
answer
70
views
InputMismatchException in a scanner to get data from txt file
I'm trying to read the highscores of a game from a txt file and put them into an array so that another section of the program can detect a high score. Earlier I had everything declared as Int and it ...
0
votes
1
answer
566
views
Java - Input Mismatch Exception?
I'm still learning java so excuse my lack of skill here, any help is appreciated! I've been working on this java I/O project for school all day at this point and now I'm getting this input mismatch ...
0
votes
1
answer
616
views
input mismatch exception while using space in between words
I'm working on a project and I already finished it, I have really simple problem which makes me really confused. I'm trying to ask a user to enter a number from a menu and depending on that different ...
0
votes
1
answer
632
views
How to overcome Exception in thread "main" java.util.InputMismatchException
Program:
import java.util.Scanner;
public class JavaExercise1 {
static int sum, num1, num2;
static Scanner scan = new Scanner(System.in);
public static void add(){
System.out....
0
votes
4
answers
3k
views
How to prevent wrong user input on a variable?
Im currently trying to build a code that prevents wrong user input (storing a char/string to a integer, e.g.) but Im not being able to make it to work...
public static void main(String[] args) {
...
1
vote
1
answer
270
views
Why am I getting Input mismatch exception error continously [duplicate]
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
Servicecentre[] ab=new ...
0
votes
1
answer
66
views
How am I catching an InputMismatchException here?
I'm trying to catch InputMismatch exceptions and display a message that tells me where the exception occurred and what type of input is required. I need this to loop until the correct input is entered....
0
votes
1
answer
105
views
Need to create an input mismatch exception
I want to put a try/catch around the input=scanner.nextInt to throw an InputMismatchException if a letter is entered, I keep getting an infinite loop. This is the code with the infinite loop. What ...
0
votes
1
answer
30
views
Do I have to change my code to use a scanner in order for inputmismatch exception to work?
My InputMismatchException isn't working, as when I put in something like a double into the input, instead of the exception output message, it gives me:
Exception in thread "main" java.lang....
0
votes
1
answer
60
views
InputMismatchException need more inputs?
I am receiving a InputMismatchException
java ShoppingTime Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at ...
-1
votes
1
answer
93
views
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 ...
3
votes
4
answers
2k
views
java.util.InputMismatchException: For input string: "2147483648"
Below is my code
public class ExceptionHandling {
public static void main(String[] args) throws InputMismatchException{
Scanner sc = new Scanner(System.in);
int a = 0;
int ...
0
votes
2
answers
989
views
Stop infinite Loop when handling invalid user input - Java [duplicate]
I'm fairly new to programming and I'm having trouble with my program continuously looping when I try to handle a InputMisMatch exception.
I have a menu which takes in user input and then uses a switch ...
3
votes
1
answer
1k
views
Input Mismatch Exception
When I input integer numbers like 5, 7, 14 etc. everything is ok. But when I enter for example 7.5 I get an error. Where is mistake?
Exception in thread "main" java.util....
0
votes
2
answers
54
views
I keep getting an InputMismatchException even though all types are correct , what should ido?
import java.util.Scanner;
public class Messdaten {
public static double temperaturInDurchschnitt(Scanner sc){
int year= 0, month= 0 , day= 0;
String discription = "";
...
0
votes
2
answers
60
views
Why does this try statement use the catch statement? [closed]
import java.util.Scanner;
import java.util.InputMismatchException;
public class bank {
public static void login() {
double balance;
try {
boolean subtract;
...
-1
votes
1
answer
64
views
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 ...
0
votes
1
answer
268
views
Getting exception in thread "main" java.util.InputMismatchException
I am trying to take input one by one and then trying to perform operations over them. Following my code.
import java.util.Scanner;
public class PlayerRoster {
public static void main(...
0
votes
1
answer
48
views
my scanner stopped working after a couple of runs and gives me the java.util.InputMismatchException: For input string: "7642874781"
After the name, Charlie is printed out it throws the input mismatch exception and says I'm entering a string into the int scanner but it really is a number so why is it telling me it's a string?
This ...
0
votes
1
answer
236
views
HttpMessageNotReadableException and MismatchedInputException
I have a game in java called "Scotland Yard". In backend it is coded with java and frontend is coded with angular. From the beginning the game contained enums as transportation types but ...
0
votes
1
answer
30
views
InputMismatch when using Scanner in from file
Good evening. I am trying to read doubles from a file and put them into a double array. The way I have approached this is to use a Scanner.
This is my code
public static void decryption(int n, int d) ...
0
votes
3
answers
870
views
The Program still throws an InputMismatchException and exits even though its been caught
I am just learning Java and I'm struggling with Exception handling. I am trying to write a quick program that takes some inputs and exports them converted into different units.
I am using Scanner to ...