udp - NumberFormatException in Java for a string that is a number -
I am implementing socket programming using Java. I get this error.
My code is:
Public category UDPServer {public static zero main (string [] args throws exceptions {byte [] data = new byte [1024]; Byte [] SendData = New Byte [1024]; Byte [] no 1b = new byte [1024]; String number 1 string; Datagram recipient packet; String sndmsg; Int port; Datagram Socket ServerSat = New Datagram Socket (9 676); System.out.println ("UDP server is running"); Byte [] buffer = new byte [65536]; While (true) {Receive pack = new datagram packet (num1b, num1b.length); ServerSocket.receive (recievePacket); Num1String = new string (Receive packet.get data ()); Println (num1String); Println (num1String.length ()); Int number 2 = integer. Percionant (number 1 string);
I run my own UDP client:
Enter the number: Enter the number 2: 5 Enter the number 3: 4 Enter the number 4: Enter number 3: Select 1 protocol: 1. UPU 2. Data sent to TCP1 server
My server shows this:
$ Java UDPS server running UDP server Client 2 to 2 data 2 1024 "main" exception in java.lang.NumberFormatException: for input string: java.lang.NumberFormatException.forInputString (numberFormatException.java:65) on "2" Ja Va.lang.Integer.parseInt (integer at Java.lang.integer.parseInt (integer. Java 00: 027) UDPServer.main (UDPServer.java:49) $
this error Why is my string 2 not being changed?
Maybe your customer code There is a problem with, however, a simple solution for picking the first letter of num1String
:
int numbers2 = Integer.parseInt (num1String.substring (0, 1)) Will happen;
Comments
Post a Comment