Because the result will get greater than Integer.MAX_VALUE

Try this

System.out.println(Integer.parseInt("yellow", 35));
System.out.println(Long.parseLong("howareyou", 35));

and for

Long.parseLong("abcdefghijklmno",25)

you need BigInteger

Try this and you will see why

System.out.println(Long.MAX_VALUE);
System.out.println(new BigInteger("abcdefghijklmno",25));
Answer from René Link on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java numbers › understanding the numberformatexception in java
Understanding the NumberFormatException in Java | Baeldung
January 8, 2024 - In European regions, a comma may represent a decimal place. For example, “4000,1 ” may represent the decimal number “4000.1”. By default, we’ll get NumberFormatException by trying to parse a value containing a comma:
🌐
Rollbar
rollbar.com › home › how to handle the numberformatexception in java
How to Handle the NumberFormatException in Java | Rollbar
June 29, 2025 - Simply put, if you attempt to parse "hello" as an integer or "12.5" as an integer, Java throws a NumberFormatException because these strings can't be converted to the expected numeric format.
🌐
Quora
quora.com › Why-does-parseInt-give-a-number-format-exception
Why does parseInt give a number format exception? - Quora
Answer (1 of 6): Well, exception name says it all. You don't really have an integer number in that string. It might be empty string as Andrew Blowe, it might have some invalid characters. The only valid characters for the parsing are digits (0123456789) and sign characters (+-). The latter can be...
🌐
Coderanch
coderanch.com › t › 393405 › java › Integer-parseInt-NumberFormatException
Integer.parseInt : NumberFormatException (Beginning Java forum at Coderanch)
Please would someone tell me why the following Integer.parseInt statement throws a NumberFormatException: String string = properties.getProperty("flag"); int i = Integer.parseInt(string); The value of string is "0" ("zero"). The error also occurs if string is "1".
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › NumberFormatException.html
NumberFormatException (Java SE 17 & JDK 17)
January 20, 2026 - public class NumberFormatException extends IllegalArgumentException · Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format. Since: 1.0 · See Also: Integer.parseInt(String) Serialized Form ·
🌐
Java67
java67.com › 2016 › 10 › 10-reasons-of-javalangnumberformatexception-in-java-solution.html
10 Reasons of java.lang.NumberFormatException in Java - Solution | Java67
This error comes when you try to convert a String into numeric data types e.g., int, float, double, long, short, char, or byte. The data type conversion methods like Integer.parseInt(), Float.parseFloat(), Double.parseDoulbe(), and Long.parseLong() throws NumberFormatException to signal that input String is not valid numeric value...
🌐
Reddit
reddit.com › r/javahelp › integer.parseint() is bugging out on me
r/javahelp on Reddit: Integer.parseInt() is bugging out on me
December 26, 2017 -

Hey guys so I am trying to parse integer from a string in the following function and I get the following error:

Exception in thread "main" java.lang.NumberFormatException: For input string: "9876543210"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:583)
at java.lang.Integer.parseInt(Integer.java:615)
at Solution.plusOne(Solution.java:129)
at Solution.main(Solution.java:149)

Here is my following code:

    public static int[] plusOne(int[] digits)
{
    StringBuilder str = new StringBuilder();
    for(int c:digits)
    {
        str.append(c);
    }
    String num = str.toString().trim();
    System.out.println(num);
    int sum = Integer.valueOf(num)+1; //I have used Integer.parseInt(num) also
    String temp = ""+sum;
    int[] total = new int[temp.length()];
    for(int i=0;i<temp.length();i++)
    {
        total[i]=Character.getNumericValue(temp.charAt(i));
    }

    return total;
}






public static void main(String[] args)
{

    int[] arr = {9,8,7,6,5,4,3,2,1,0};
   System.out.println(plusOne(arr));

}

I am curious where I am going wrong here since I am pretty sure my string sum does not have any spaces or characters. Any help would be appreciated!

Find elsewhere
🌐
Reddit
reddit.com › r/javahelp › java throws numberformatexception with "9646324351"
r/javahelp on Reddit: Java throws NumberFormatException with "9646324351"
April 7, 2022 -

The string somewhy isn't converting to int.

Here is an error message:

Exception in thread "main" java.lang.NumberFormatException: For input string: "9646324351"

	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
	at java.base/java.lang.Integer.parseInt(Integer.java:660)
	at java.base/java.lang.Integer.parseInt(Integer.java:778)
	at com.company.Main.reverse(Main.java:143)
	at com.company.Main.main(Main.java:24)
🌐
GeeksforGeeks
geeksforgeeks.org › java › numberformatexception-in-java-with-examples
NumberFormatException in Java with Examples - GeeksforGeeks
July 23, 2025 - public static int parseInt(String s, int radix) throws NumberFormatException This function parses the string argument as a signed integer in the radix specified by the second argument.
🌐
JetBrains
youtrack.jetbrains.com › issue › IDEA-294151 › java.lang.NumberFormatException-For-input-string-at-Integer.parseInt
java.lang.NumberFormatException: For input string
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
Medium
medium.com › thefreshwrites › how-to-handle-numberformatexception-acc1bb1f658f
How To Handle NumberFormatException in Java | by Mouad Oumous | The Fresh Writes | Medium
February 17, 2024 - public static int parseInt(String s, int radix) throws NumberFormatException This function parses the string argument as a signed integer in the radix specified by the second argument.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › lang › NumberFormatException.html
NumberFormatException (Java SE 11 & JDK 11 )
January 20, 2026 - public class NumberFormatException extends IllegalArgumentException · Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format. Since: 1.0 · See Also: Integer.parseInt(String), Serialized Form ·
🌐
CodeQL
codeql.github.com › codeql-query-help › java › java-uncaught-number-format-exception
Missing catch of NumberFormatException — CodeQL query help documentation
Methods such as Integer.parseInt that parse strings into numbers throw NumberFormatException if their arguments cannot be parsed.
🌐
GitHub
github.com › hzi-braunschweig › SORMAS-Project › issues › 2312
Integer.parseInt: NumberFormatException: For input string: ...
143 more Caused by: java.lang.NumberFormatException: For input string: "080349ddddd" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:583) at java.lang.Integer.parseInt(Integer.java:615) at de.symeda.sormas.backend....
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › NumberFormatException.html
NumberFormatException (Java Platform SE 8 )
October 20, 2025 - public class NumberFormatException extends IllegalArgumentException · Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format. Since: JDK1.0 · See Also: Integer.parseInt(String), Serialized ...
🌐
Blogger
javarevisited.blogspot.com › 2016 › 08 › javalangnumberformatexception-for-input-string-null-java.html
How to fix java.lang.numberformatexception for input string null - Cause and Solution
The error "Exception in thread "main" java.lang.NumberFormatException: For input string: "null" is specifically saying that the String you receive for parsing is not numeric and it's true, "null" is not numeric. Many Java methods which convert String to numeric type like Integer.parseInt() which is used to convert String to int, Double.parseDoble() which convert String to double, and Long.parseLong() which convert String to long throws NumberFormatException to inform that the input String is not numeric.
Top answer
1 of 2
2

Your field is empty and you are trying to convert an empty string into a number (via parseInt()). That's what is causing the NumberFormatException.

To avoid that kind of exception, you should validate your field. You can write a simple check testing if it's empty by asserting that the length() of the input String returned by getText() is greater than zero.

You can check if it is a number writing a regular expression

String possibleNumber = yourField.getText();
boolean isNumber = Pattern.matches("[0-9]+", possibleNumber);
if(isNumber) {
   number = Integer.parseInt(possibleNumber);
}

But you shouldn't be reading data in the constructor in the first place. Write an event handler to capture the action event of pressing the button, and in it read the data.

yourButton.addActionListener(new ActionListener() {
    yourText = field.getText();
}); 
2 of 2
2

This exception say :

java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)

your input string here is set to "" aka an empty String and then you try to parse the "" into an int. And that is not possible and therefore the error.

Make sure you pass in correct numbers like 1 2 3 or something and with no dots like 1.2 because that aswell will give an error.

You should also add some logic so its not possible to pass in an empty string or catch the empty string or a double value. Because it will cause this exception everytime user does not input a correct number format.

🌐
Dot Net Perls
dotnetperls.com › parseint-java
Java - parseInt: Convert String to Int - Dot Net Perls
ParseInt can lead to complex problems—it throws a NumberFormatException on invalid data.