Results 1 to 4 of 4
  1. #1
    bharatgs7 is offline Member
    Join Date
    Jan 2012
    Posts
    1
    Rep Power
    0

    Default Exception while converting string to integer

    Hello friends,
    I am trying to convert string to Int but i am getting exception as java.lang.NumberFormatException: For input string: ""
    Code is as follows

    String no=request.getParameter(itemno); // here itemno varies everytime...sometime it will be 1 and sometime it will be 2 but in string format
    String itemn[]=no.split(" ");
    int itemNo=Integer.parseInt(itemn[0]);

    Can anyone solve this problem for me??

    Thanks in advance

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default Re: Exception while converting string to integer

    Why are you doing the split?
    Print out the value of 'no', like:
    System.out.println(">" + no + "<");
    SO you can spot spaces etc.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,256
    Rep Power
    19

    Default Re: Exception while converting string to integer

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Converting J001 to integer
    By jaylimix in forum New To Java
    Replies: 4
    Last Post: 12-15-2011, 11:08 PM
  2. Replies: 2
    Last Post: 11-27-2011, 05:11 PM
  3. Converting a 2's complement to the proper integer
    By Chuklol in forum New To Java
    Replies: 1
    Last Post: 10-10-2011, 05:47 AM
  4. Converting an integer into a BigInteger
    By mzjazzygirl in forum New To Java
    Replies: 27
    Last Post: 09-23-2010, 06:37 PM
  5. Replies: 24
    Last Post: 05-18-2009, 10:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •