gpt4 book ai didi

将字符串解析为 double 时出现 android 错误

转载 作者:行者123 更新时间:2023-11-29 18:19:07 24 4
gpt4 key购买 nike

enter code here

06-27 00:34:04.641: ERROR/AndroidRuntime(13633): FATAL EXCEPTION: main
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): java.lang.RuntimeException: Unable to start activity ComponentInfo{yaraby.y/yaraby.y.ghost}: java.lang.NumberFormatException:
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at android.app.ActivityThread.access$2300(ActivityThread.java:126)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at android.os.Handler.dispatchMessage(Handler.java:99)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at android.os.Looper.loop(Looper.java:123)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at android.app.ActivityThread.main(ActivityThread.java:4633)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at java.lang.reflect.Method.invoke(Method.java:521)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at dalvik.system.NativeStart.main(Native Method)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): Caused by: java.lang.NumberFormatException:
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:267)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at java.lang.Double.parseDouble(Double.java:287)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at yaraby.y.ghost.onCreate(ghost.java:89)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
06-27 00:34:04.641: ERROR/AndroidRuntime(13633): ... 11 more

第89行是

enter code here
Double p1= Double.parseDouble(x);

我从服务器接收到的是字符串,我希望它是 double 的并且它已经是 double 字但作为字符串接收

enter code here
String x=inFromServer.readLine();
String y=inFromServer.readLine();


x=x.trim();
Double p1= Double.parseDouble(x);
y=y.trim();
Double p2= Double.parseDouble(y);

最佳答案

字符串是否包含“.” (如 123.45)或“,”(如 123,45)?

您应该根据您的区域设置替换它。 Try catch block 也可以工作。

关于将字符串解析为 double 时出现 android 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6487198/

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