Thread: ParseInt

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Kiev, Ukrain
    Posts
    88
    Rep Power
    2

    ParseInt


    Hello!
    I got a problem with parseInt .
    java.lang.NumberFormatException: For input string: ""

    The thing is i don't have "" such characters . And , as i think this is not a character at all!

    here is my code:

    Code:
    public static int[] spliter(String str){
    		
    		int k = 0;
    		int[] result = new int[3];
    		int n = 0, c = 0, m = 0, num = 0;
    		String bN= new String(), bC=new String(), bM=new String(); // here i declaring the buffer strings
    		
    		for(int i = 0; i< str.length(); i++){
    			if( k == 0 ){
    				if( str.charAt(i) != ' ' ){
    					bN += str.charAt(i); //i'm filling them here
    				}
    				if( str.charAt(i) == ' ' ){
    					k = 1;
    					i++ ;
    				}
    			}
    			if( k == 1 ){
    				if( str.charAt(i) != ' ' ){
    					bC += str.charAt(i);// + here
    				}
    				if( str.charAt(i) == ' ' ){
    					k = 2;
    					i++ ;
    				}
    			}
    			if( k == 2 ){
    				if( str.charAt(i) != ' ' ){
    					bM += str.charAt(i);// + here
    				}
    				if( str.charAt(i) == ' ' ){
    					k = 0;
    				}
    			}
    		}
    		
    		result[0] = Integer.parseInt(new String(bN));
    	  	result[1] = Integer.parseInt(new String(bC));
    	  	result[2] = Integer.parseInt(new String(bM));// here i'm parsing my int-s from strings
    		return result;
    	 }
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    When you get that error, it means you are trying to parse an empty String.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Kiev, Ukrain
    Posts
    88
    Rep Power
    2
    Originally Posted by bullet
    When you get that error, it means you are trying to parse an empty String.
    Yes , i know that. From the error log . but normal output of this function are integers, without any spaces or empty strigns.
  6. #4
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    Originally Posted by FAQer
    Yes , i know that. From the error log . but normal output of this function are integers, without any spaces or empty strigns.
    Yes the output is an integer, but you can't parse an empty String.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Kiev, Ukrain
    Posts
    88
    Rep Power
    2
    Originally Posted by bullet
    Yes the output is an integer, but you can't parse an empty String.
    Okay , thank you. I've found my error already. One of my integers were absent.

IMN logo majestic logo threadwatch logo seochat tools logo