Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.lang.NumberFormatException

843810May 14 2006 — edited May 15 2006
this my code
import java.io.*; 
import java.net.*; 
import java.*;

class UDPServer 
{ 
  public static void main(String args[]) throws Exception 
  { 
 UDPServer t = new UDPServer();
      DatagramSocket serverSocket = new DatagramSocket(5551);


while(true) 
        { 
  
       DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); 
       serverSocket.receive(receivePacket); 
   
       String sentence = new String(receivePacket.getData()); 
   
for (i=0;i<sentence.length();i=i+2){
         	
     	 char letter1= sentence.charAt(i);  
        	String u = h.valueOf(letter1);
                  time = (Integer.parseInt(u));       	   
        	   char letter2= sentence.charAt(i+1)
                       char letter3= sentence.charAt(i+2);

 u2 = h.valueOf(letter2);
   	     //	try{
   	     time2 = (Integer.parseInt(u2));
   	//  }catch(NumberFormatException ex){System.err.println("error2");}
   	     time = 1000*(10*time+time2);
   	    i++;
 if (letter3==('F')){  
       
          	System.out.println ("this is F");
          
     	//	p5.write(240);
     		   
     		   try {
			Thread.sleep(time);
				   } 
		
		catch (InterruptedException ie) {}
//		p5.write(0); // To stop after the movement
				         	
        			      }
         	
//------------------------------------------       
       
       
       else if (letter3==('B'))
		{
			System.out.println ("This is B");
			//	p5.write(160);
				
				try 
		{
			Thread.sleep(time);
		} 
		catch (InterruptedException ie) {}
//		p5.write(0); // To stop after the movement
		}
         	
//--------------------------------------------
         	
       else if (letter3==('L'))
       {
       	 // p5.write(192);
       	 			System.out.println ("This is L");

       	  
       	  try 
		{
			Thread.sleep(time);
		} 
		catch (InterruptedException ie) {}
//		p5.write(0); // To stop after the movement
       }
         	
//---------------------------------------------
         
       else if (letter3==('R'))
       {
//       	  p5.write(48);
			System.out.println ("This is R");

       	  
       	  try 
		{
			Thread.sleep(time);
		} 
		catch (InterruptedException ie) {}
//		p5.write(0); // To stop after the movement
       }
       
//-------------------------------------------------       

       else if (letter3==('S'))
       {
//       	  p5.write(0);
			System.out.println ("This is S");

       	  
       	  try 
		{
			Thread.sleep(0);
		} 
		catch (InterruptedException ie) {}
		
       }



}	


}
}
}


when I send the input "12F" the following client program

import java.io.*; 
import java.net.*; 
  
class UDPClient { 


    public static void main(String args[]) throws Exception 
    { 
  
		boolean send =true;
      	BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); 
  
		DatagramSocket clientSocket = new DatagramSocket(); 
  
		InetAddress IPAddress = InetAddress.getByName("coe-347B-Fac"); 
  
      byte[] sendData = new byte[1024]; 
      byte[] receiveData = new byte[1024]; 
      
      while(send){
  		System.out.println ( " Please Enter String You Want to Send : " );
      String sentence = inFromUser.readLine(); 
      sendData = sentence.getBytes();   
      DatagramPacket sendPacket = 
         new DatagramPacket(sendData, sendData.length, IPAddress, 5551); 
  
      clientSocket.send(sendPacket); 
    }
  
 
      clientSocket.close(); 
      } 
}
after execution this input it exit and do not take onther input. it give me this output
******************************
this is F
Exception in thread "main" java.lang.NumberFormatException: For input string: "
"
at java.lang.NumberFormatException.forInputString(NumberFormatException.
java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.parseInt(Integer.java:497)
at UDPServer.main(UDPServer.java:51)
***********************************************

So what is the problem????
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 12 2006
Added on May 14 2006
1 comment
396 views