NumberFormatException 1 « Number Format « Java Data Type Q&A

1. Why this NumberFormatException?

Ihave this stack trace (part of)

Servlet.service() for servlet action threw exception
java.lang.NumberFormatException: For input string: "37648"
 at java.lang.NumberFormatException.forInputString(
 at java.lang.Long.parseLong(
 at java.lang.Long.valueOf(
 at java.lang.Long.decode(
in one of my logfile I don't know what was ...

2. Why does trying to parse this value result in a NumberFormatException?


String myVar = "1255763710960";
int myTempVar=0;
   myTempVar = Integer.valueOf(myVar);
catch (NumberFormatException nfe)
For input string: "1255763710960"
I have absolutely no idea why this is.

3. How can I avoid a NumberFormatException in Java?

i searched, i found, but it all didn't work. my problem is that the NumberFormatException is thrown while I want to cast from String to double. The string array atomized contains many ...

4. Should I catch this NumberFormatException in a method?

Assumption that I have method like

void A(long input) {


Basically, it works well when the input is long or could succeed convert other types to long. But, when some wrong data ...

5. What is the proper way to handle a NumberFormatException when it is expected?

I'm running into this situation where I need to parse a String into an int and I don't know what to do with the NumberFormatException. The compiler doesn't complain when ...

6. Long.parseLong("digitstring too significant") produces java.lang.NumberFormatException

I get a java.lang.NumberFormatException: For input string: "1.7023484830876092" trimming the string to 1.70234, does solve the problem, but before slicing the string myself I'm wondering whether its possible to use some ...

7. java.lang.NumberFormatException on parsing with commons-digester

I get a java.lang.NumberFormatException, while parsing a xml file with commons-digester. Not sure what it means:

Caused by: java.lang.NumberFormatException: For input string: "flickrmeetup rochester dan totheright 200701"
    at java.lang.NumberFormatException.forInputString(

8. java.lang.NumberFormatException: For input string: "null"

I'm parsing a doc and I get the following error:

Exception in thread "main" java.lang.NumberFormatException: For input string: "null"
    at sun.misc.FloatingDecimal.readJavaFormatString(
    at java.lang.Float.valueOf(

9. java.lang.NumberFormatException: For input string: " "

java.lang.NumberFormatException: For input string: " " I get this error when I try to do this: total = Integer.parseInt(dataValues_fluid[i]) + total; Some of the values are " ". So thats why it gives ...

10. java.lang.NumberFormatException: For input string: "20110328094108069414"

Am trying to convert a String value to long, and am getting : java.lang.NumberFormatException: For input string: "20110328094108069414" My code :

  String buyId  = "PSFT_20110328114728073793";
  long bookId  = ...

11. How to print diff Msg for same NumberFormatException on diff cause in JAVA?

How to print diff Msg for same NumberFormatException on diff cause in JAVA?

try {
 int a=Integer.parseInt(aStr);
int b= Integer.parseInt(bStr);
}catch (NumberFormatException ex) { 
 if ex's cause is from int a;//ex.getCause()=a?
System.out.println("a is not ...

12. Java API Design: NumberFormatException for Method that Parses a Semi-Numeric String?

I'm making a library that contains a few methods for parsing string dates and times. I am having difficulty deciding what exception those methods should throw when the string argument ...

13. why Java throws a NumberFormatException

I got an exception while parsing a string to byte

String Str ="9B7D2C34A366BF890C730641E6CECF6F";

String [] st=Str.split("(?<=\\G.{2})");

byte[]bytes = new byte[st.length];
for (int i = 0; i <st.length; i++) {
 bytes[i] = Byte.parseByte(st[i],16);

14. Getting Error java.lang.NumberFormatException: For input string: "16.0"

I want to convert the cell value into int value so i am trying following code:

for (int chk1 = 1; chk1 < m; chk1++ ) {
   int intCounter ...

15. Why NumberFormatException is Runtime?

Runtime exceptions indicate broken contract (like NPE) and should never be thrown if code has no errors. It always indicates error in code (same as asserts but asserts are for internal ...

16. org.apache.jasper.JasperException: java.lang.NumberFormatException: null

I got exception: org.apache.jasper.JasperException: java.lang.NumberFormatException: null when trying this code:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>


17. NumberFormatException in InputString

Please help me solve this exception:-

String strBinary="100000000000000001000000000000000000000000000000000000000000000000000000";
        System.out.println("length is " + strBinary.length()); 
        long intParse=Long.parseLong(strBinary, 2);

18. Throwing a custom NumberFormatException in Java

I am trying to throw my own NumberFormatException when convrting a String month into an Integer. Not sure how to throw the exception. Any help would be appreciated. ...

19. parseDouble in Java results to NumberFormatException

I am trying to load info from a properties file and i have the following code:

anInt = Integer.parseInt(prop.getProperty("anInt"));
aDouble = Double.parseDouble(prop.getProperty("aDouble"));
and while the first line works just fine, the second one where ...

20. why i'm getting lang.string.NumberFormatException for input string ""

assigning a string value to a numeric variable will definately raise this kind of exceptions.... eithier you parse the string value to a int or float or any numeric value... like ...

21. about NumberFormatException

Employee ID : <%= session.getAttribute("ID") %>     

23. NumberFormatException

24. NumberFormatException

25. problem NumberFormatException For input String ""

HI, I am coding a menu system the basic idea is that I have a main menu and then other sub menu's and each one has option to return to main. The code works fine until I try to return to the main menu from one of the sub menu's. I think this is due to the lines: String sc=in.readLine(); int ...

26. NumberFormatException

Hi everyone, I need some help. I have a program that creates a window with JTexboxes on it and a button. The user is to fill in the textboxes and press the button. When this occurs the program is to retreive the information from the textboxes and then insert it into a database. I used getText() to get the information from ...

27. how to avoid NumberFormatException

As we know, while parsing a string in to int/floal by using the method Integer.parseInt(String s)/Float.parseFloat(String s), it will return int/float value, if the String contains any numeric value like "101" or "101.11". but if it is not numeric like "a12", then it will throw NumberFormatException. Please let me know, is there way to avoid this Exception except handling the exception ...

28. NumberFormatException

hello. I'm wondering if anyone can help me out with my simple yet not so simple to me problem. I have a try { //my code goes here catch(NumberFormatException ex) { jTxtArea.append("Cannot have a negative Number: " + ex.getMessage()+"\n"); } } In the try I have set up a few text fields to recieve input, among them I have a numeric ...

29. NumberFormatException

I am getting this exception when my textfield is empty. What can I do to fix the problem? I start out with numbers in getText() but when I remove the last one I get the exception. This is the code where the error is happening. protected void postRemoveUpdate ( DefaultDocumentEvent evt ) { super.postRemoveUpdate ( evt ); //System.out.println ( "Document has ...

30. NumberFormatException HOW CAN I TELL WHERE IS THE PROBLEM?

int i; int x; String itsMe = ""; try { itsMe = "i"; i = Integer.parseInt(args[0]); itsMe = "x"; x = Integer.parseInt(args[1]); } catch (NumberFormatException e) { System.out.println(" Error in " + itsMe + " " + e); StackTraceElement[] myTrace = e.getStackTrace(); TraceLoop: for (int k = 0; k < myTrace.length; k++) { if (myTrace[k].getClassName().equals("prog30")) { System.out.println( "Error at line " ...

31. NumberFormatException

Hi, I am doing input from the keyboard and want to safeguard against accidental pressing of the key without any value having been entered first. I have some simple code here (for demo purposes), and tried to check when it crashes, but don't see a pattern yet (or rather, I see it, but I don't understand it). This, for example, ...

32. NumberFormatException problem

I suspect the key is that you're on IRC, and people are typing funny. It's hard to tell the difference between a "1" (numeral one) and an "l" (letter ell) in many fonts. Are you sure you don't have four ell, four ell? You could try System.out.println((int) varB.charAt(1)); The code for "one" is 49; anything else isn't!

33. Who throws NumberFormatException

I'm not sure if such a list is available. That particular information doesn't seem very useful to me. However, the Java API documentation DOES tell you what exceptions are thrown by each individual method. In my opinion, this is much more useful to know when you are programming in Java. Of course, I may just be stuck in my way of ...

34. HiLo game and NumberFormatException

i'm crafting this game; all went well till the point where things can go wrong: user's input is not an int... where/how should i manage it? i tried a try/catch block, but since my method returns an int i'm forced to return some int... so i returned -1, but wont work either here's my code:import*; public class LinhaDeComando { private ...

35. NumberFormatException

public void mouseClicked(MouseEvent me) { String name = titleBox.getText(); String gname = genre.getText(); String year1 = year.getText(); int year2 = Integer.parseInt(year1); String actor = actorBox.getText(); String length1 = length.getText(); int length2 = Integer.parseInt(length1); String audio1 = audioBox.getText(); double audio2 = Double.parseDouble(audio1); if(me.getComponent() == clear) clearText(); else if(me.getComponent() == accept) { film = new Film(name, gname, year2, actor, length2, audio2); films.addElement(film); try ...

36. java. lang. NumberFormatException ?

37. NumberFormatException

38. NumberFormatException

39. numberformatexception

Can anybody help me how to solve the numberformatexception.. I have a form in which i have different types of field.One of them is to input the number in the textfield. After i submit the form,I get that value using the following code in anothor jsp page. String totalpages = request.getParameter("totalpage"); int totalpage = Integer.parseInt(totalpages); But the problem is that,when i ...

40. NumberFormatException

Dear sir, I want to take input from a file and the file value is double. Here is the file graph1 contains- 0.001.00 0.50.75 1.002.00 1.002.00 1.504.75 2.009.00 And my Java program is- import*; public class Area{ static double[]x; static double[]y; public static void main(String...args) throws Exception{ FileReader fread = new FileReader("graph1"); BufferedReader br = new BufferedReader(fread); String str; String ...

41. NumberFormatException: null

I'm trying to write a program to perform some of the some of the functionality of StringTokenizer for an assignment, my instructor provides the driver and I do the rest. I've gone about as far as I can but I keep hitting a "NumberFormatException: null" run time error when trying to run the driver. I did some digging around and it ...

42. Why NumberFormatException?

43. java.lang.NumberFormatException

45. java.lang.NumberFormatException: For input string: ""

Hello, If month or year is null then the following code throws exception java.lang.NumberFormatException: For input string: "" String errorCheck=cm.addExpErrorCheck( employer, countryId, bType, sMonth, sYear, eMonth, eYear, jobTitle, shortDesc, sEquipments); -------------------------------------------------------------- if(DateManager.dateTest("01",sMonth,sYear,"01",eMonth,eYear).equals("1")){ error[10]="Start date cannot be greater than end date or today's date"; } -------------------------------------------------------------- public static String dateTest( String days, String months, String year, String days1, String months1, String year1){ ...

46. NumberFormatException : null

Please help Im not able to find wheres the problem and how to resolve import*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; import javax.sql.*; import java.util.*; import java.util.regex.*; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.*; import javax.naming.*; public class addEmp extends HttpServlet { @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); boolean isMultipart = ServletFileUpload.isMultipartContent(request); ...

47. Why am i getting NumberFormatException

48. java.lang.NumberFormatException: For input string: "139.56"

If you read the API, it says "The argument is interpreted as representing a signed decimal byte, exactly as if the argument were given to the parseByte(java.lang.String) method." If you then follow the link to that method, you'll see this: "The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign ...

51. NumberFormatException raised

52. NumberFormatException

i am trying to store a value to a file. this value is very small and i format it using DecimalFormat class. For instance my value is and i format it using this constructor The formatted value is stored in a file When i try to retrieve this value i get the NumberFormatException:( How can i deal with this kind of ...

53. NumberFormatException: empty String

54. NumberFormatException error

SEVERE: Servlet.service() for servlet jsp threw exception java.lang.NumberFormatException: For input string: "" this type of error is coming... i put text box...the text box should not emptly submitted for that the pop up window will open and give a msg please enter id like that ... i am using jsp and script in that ...

55. Custom exception exits program, while NumberFormatException only shows error

I created an exception called NegativeNumberException as a test from a book I am reading. The code is as follows: class NegativeNumberException extends Exception { public NegativeNumberException() { super(); } public NegativeNumberException(String msg) { super(msg); } } My code "trys" a block of code and catches two possible exceptions: try { // code of program } catch (NumberFormatException nfe) { System.out.println("Error: ...

56. java.lang.NumberFormatException: null

Hi, How can I compare null value in string array. I want escape null elements. private static void arrange(String[][] arr1) { for (int i=0;i<=count;i++) { for(int j=0;j"+m); } } ...

57. How to remove numberformatexception for string??

import*; import java.util.regex.*; class showfile { public static void main(String args[]) throws Exception { int i=1; int j=0; FileInputStream fin = new FileInputStream("empty"); DataInputStream in=new DataInputStream(fin); BufferedReader br=new BufferedReader(new InputStreamReader(in)); String strline=null; String[] dummy=null; String x=null; int y=0; while ((strline=br.readLine())!= null) { if(i>1) { int c=1; System.out.println(strline); dummy=strline.split(","); try{ while(c<3) { x=dummy[c]; y=Integer.parseInt(x); System.out.println(y); c++; j++; } }catch(NumberFormatException e){ System.out.println("Number ...

58. java.lang.NumberFormatException: For input string: ""

If you need more specific help, you'll want to give us a lot more information about your problem including your code, your data, what you're trying to achieve and what's not happening. Please read the link in my signature link on how to ask smart questions to see what kind of information will help us best help you.

59. ERROR java.lang.NumberFormatException: For input string: "responsibleName"

I have a request like this: str = "select a.responsibleName," + " a.responsibleInfo," + " a.responsiblePhone," + " a.responsiblePhoneFax," + " a.responsibleEmail " + " from RegistrationCardOffice a " + " where a.user.userId = "+ code + " group by a.responsibleName, a.responsibleEmail, a.responsiblePhone, a.responsiblePhoneFax, a.responsibleInfo"; Result of it is stored in ListDataModel(); Then I have a dataTable on page.

60. java.lang.NumberFormatException: null

61. NumberFormatException

62. NumberFormatException

Perhaps you could post the stack trace, exactly as you see it. And indicate which line of your code it is referring to. If you are wondering why parseDouble() is throwing an NFE you can always try using System.out.println() to print the string before you parse it. You can only sucessfully parse strings that are valid numerals.

63. java.lang.NumberFormatException: null

// Get the wine catalog WineCatalog catalog = (WineCatalog) application.getAttribute( "WineCatalog"); // If the shared product catalog hasn't been created yet, create it if (catalog == null) { // synchronize this to make sure only one // thread stores the catalog. synchronized (application) { // get data from JDBC catalog = WineCatalogDAO.getAll();

64. NumberFormatException

I have this small program in which the user has to enter an integer but suppose he types "forty two". This will throw a NumberFormatException but I have defined my OWN exception: InvalidNumberException (extends NumberFormatException). When I run my program, instead of throwing my InvalidNumberException, it throws the NumberFormatException. What can I do so that the program throws my exception?

65. try catch NumberFormatException?

hi how do i use try catch NumberFormatException? i like to validate that the variable to only accept int and not String or other combination of character. how can i do so with try and catch ? and i need it to loop back to Enter Questionnaire again if the input is invalid. Do i use a do while loop for ...

66. NumberFormatException

67. parseInt and NumberFormatException

68. problem with parseDouble numberformatexception...

Look at your line: tempString.substring(tempString.lastIndexOf("=")+1); Does it do anything to tempString? Look at the String API subString method? Does it mutate the String that calls it? or does it rather return a result? hmmmmmmm Also look at your error message, is it being passed your expected truncated string? hmmmmmm again. You're close, but not there. Addendum: too slow again!! Message was ...

69. NumberFormatException

70. NumberFormatException

As far as I can see, you try to process the content of 'txtVideoBal' but since you do not display it and therefore fill it you cannot parse the content. You would do well to print a stack trace when you get an exception that you handle. By doing this it took me less than a minute to find this bug. ...

71. NumberFormatException

NumberFormatException means that the string you are trying to parse doesn't contain only numbers. Try printing the string out before you try to parse it. It seems like there must be a better way to get the value you are trying to get. What exactly is it you are trying to do?

72. What does java.lang.NumberFormatException error means?

Hi All, Before I begin I would like to thank you good programmers for your answers and help through the years. My problem is that I am getting the above error. I have a 4275327488 in a string and when I convert it into a int I am encountering this error at run time. if(ii

73. RTFEditorKit produce NumberFormatException

I need to convert rtf content to StyledDocument. I am using String message = "\test-java"; StringReader sread = new StringReader(message); StyledDocument std = new DefaultStyledDocument(); RTFEditorKit kit = new RTFEditorKit();, std, 0); But this is not working fine. This code produce java.lang.NumberFormatException: For input string: "-". I dont know what bug is this.

75. NumberFormatException

76. NumberFormatException Error

77. NumberFormatException and getMessage()

78. NumberFormatException

int i = 0; while(i <= _totalPages ){ try{ PortletURL actionURL = res.createRenderURL(); actionURL.setPortletMode(req.getPortletMode()); actionURL.setParameter("action", "list"); actionURL.setParameter("page", String.valueOf(i)); pageURLS.put(++i, actionURL); }catch(PortletModeException e){ _log.debug(e); } } mav.put("pageurls", pageURLS); String page = req.getParameter("page"); try{ _currentPage = Integer.parseInt(page); }catch(Exception e){ _log.debug("page = " + page); _log.debug(e); _currentPage = 1; } mav.put("currentPage", _currentPage); The errors i'm getting are DEBUG 09:05:58 attachmenttype.ViewListController:176 - page = null ...

79. java.lang.NumberFormatException

80. NumberFormatException

hey All, Can any1 help me out regarding a field which is number as per SQL, while from frontend I am taking it as : String empl_cont_no_fe = request.getParameter("empl_cont_no"); and converting into Integer as : int empl_cont_no_fe1 = Integer.parseInt(empl_cont_no_fe); and using it to insert into SQL by below commnad : st.setInt(3,empl_cont_no_fe1); but in this I am not able to enter 10 ...

81. java.lang.NumberFormatException ?

Hi, I am playing with Algorithms in Java by Robert Sedgewick and somehow got stuck by the auxilary file. The following are the file and my test file When I run the, I got Exception in thread "main" java.lang.NumberFormatException: For input string: " ?? import*; public class In { private static int c; private static ...

82. Java NumberFormatException

Hi, I am trying to parse a string (accountNo) to an int. accountNo is holding the number 12345678911. A number format exception is being thrown. any ideas why? void add(String name, String accountNo){ UserAccount createdNode = new UserAccount(); UserAccount actualNode = new UserAccount(); actualNode = head; try{ int test = Integer.parseInt(accountNo.trim()); }catch(Exception e){ System.out.println(e); } int test2 = Integer.parseInt(head.getAccountNo());

83. java.lang.NumberFormatException: null

You post title says NumberFormatException, but the actual message you post is a NullPointerException. So which one is it? Anyway, look at line 31 of (a terrible name for a Java source file, by the way. Especially since the class contained in it must have the same name). Something on that line is null.

84. java.lang.NumberFormatException after use of StringTokenizer

oups, sorry, I forgot to put them in the message. The error message is the following : Exception in thread "main" java.lang.NumberFormatException: For input string: "497604.122" at sun.misc.FloatingDecimal.readJavaFormatString( at java.lang.Double.parseDouble( at lecture.main( When looking at the variable Xstr1 using the debugger, it indicates the following : Xstr1 "497604.122"(id=24) -count 21 -hash 0 -offset 36 -value char[81] (id=25), which is [, C, ...

85. Why am I java.lang.NumberFormatException: multiple points on parsing a long

All reasonable suggestions, and I have now added some debugging information to try and get the corresponding value when it occurs. But I've had the same error for a non trivial SimpleDateFormat case as well, so Id really like to know what value could possible cause this error to occur, could the problem be related to the users Locale ?

86. Weird java.lang.NumberFormatException

Let's see 1) a small input file that will reproduce your error. 2) a repost of your code using proper code tags (frankly, I'm a little surprised that after 130 posts you haven't learned to edit your post if it isn't formatted correctly) OK, ignore # 2) -- thanks for formatting your code as I typed this. Edited by: Encephalopathic on ...

87. NumberFormatException

88. NumberFormatException: empty String

89. java.lang.NumberFormatException: For input string

Hi Finally i got it.. Here by i am posting code : public static void main(String args[]) throws IOException { File file = File.createTempFile("UID", null); file.deleteOnExit(); String s = file.getName(); System.out.println("s:"+s); String substring = s.substring(3, s.indexOf('.')); System.out.println("substring:"+substring); int it = Integer.parseInt(substring); System.out.println("it:"+it); } When i run this code on java 6 update 7. s : UID16.tmp substring:16 it:16 Now when switch ...

90. NumberFormatException problem

91. java.lang.NumberFormatException: null

92. java.lang.NumberFormatException thrown in 1.6.0_10-rc

Hi, One of our applet throw java.lang.NumberFormatException when we run with the latest 1.6.0_10-rc JRE. The code is as follows, public int xxx(String dateTimeInMilliseconds) { ... serverTime = Calendar.getInstance(TimeZone.getTimeZone(TimeZone.getAvailableIDs(8 * 60 * 60 * 1000)[0])); //GMT+8, timezone of HK serverTime.setTime(new Date(Long.parseLong(dateTimeInMilliseconds))); // java.lang.NumberFormatException thrown here ... where dateTimeInMilliseconds is set using Date().getTime() in other Class When we run the applet, it ...

93. java.lang.NumberFormatException: For input string:"1.7 - (1)"

Can anyone suggest on this??? Problem : I have a report which display low/highest info for each record in a jsp page. using servlet i call a stored procedure which returns data back depending on various criteria & added into a vector is a hash map key/value pairs for each column data. Once the data is in servlet i am using ...

94. Re: Getting java.lang.NumberFormatException Error, need help

Look at the full stack trace. At some point it should list your own code. Find the first line in your code listed in the stack trace. Somewhere there, you try to parse a string to get a number. But you're passing an empty string to the code doing the parsing. So find out how you ended up with an empty ...

95. java.lang.Numberformatexception

You're trying to parse a String representation of an integer with arbitrary size to an int (with fixed maximum size). Integer.parseInt() tries to parse an int from the String you give it. Seeing as the String represents a number way bigger than can be represented by an int, it throws an error correctly. The real WTF lies in you parsing a ...

96. NumberFormatException

Calling readLine on a BufferedReader and then operating on it as if you have a String without checking is begging for trouble. When the EOF is hit that method will return a null. Which will cause your code to blow up. You should add some tracing to see what the values are, that you are reading the file you think you ...

97. NumberFormatException

98. NumberFormatException Just curious

My question pertains to the behaviour of Integer and BigInteger. If I have something like this String value = "99999999999"; Integer i = new Integer(value); return i.intValue(); I get a NumberFormatException which is ok. If I do the same with BigInteger instead of Integer, the value overflows, quietly wraps around and returns 1215752191. I looked at the source for BigInteger and ...

99. NumberFormatException

100. java.lang.NumberFormatException: For input string: "20.0000"

%!PS-Adobe-3.0 EPSF 3.0 %%BoundingBox: 0 0 612 792 %%Title: Developmental Testing %%CreationDate: 06/07/2007 08:45:57 %%EndComments /Helvetica findfont 9 scalefont setfont 0.5 setlinewidth 0.0 setgray 20.0000 20.0000 moveto 592.0000 20.0000 lineto / 592.0000 772.0000 lineto / 20.0000 772.0000 lineto / 20.0000 20.0000 lineto / stroke clear 22.0000 22.0000 moveto 590.0000 22.0000 lineto / 590.0000 770.0000 lineto / ...