gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 08:27:06 30 4
gpt4 key购买 nike

当我运行此 Java 代码时:

public void run(){
String stringPacketData=null;
try {
stringPacketData = new String(clientPacketData,"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
System.exit(1);
}
String[] splitString=stringPacketData.split("@");
this.clientID = Integer.parseInt(splitString[0]);
String op="";

op=splitString[1];
if(op.equalsIgnoreCase("popola_cache")){
popolamentoCache(Integer.parseInt(splitString[2]));
}
else{
System.exit(0);
}
}

如果 stringPacketData 的格式为:idClient@operationType@dimCache,则会抛出以下异常:

Exception in thread "Thread-2" java.lang.NumberFormatException: For input string: "5"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at UDPSocketBased.WorkerUDP.run(WorkerUDP.java:53)

WorkerUDP.java:53语句对应于: popolamentoCache(Integer.parseInt(splitString[2]));

我不明白为什么我的输入字符串“5”的格式不正确。

最佳答案

首先,您需要在尝试解析字符串之前修剪它

this.clientID = Integer.parseInt(splitString[0].trim());

关于java.lang.NumberFormatException : For input string: "5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29648012/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com