NumberFormatException - 如果机器人 [英] NumberFormatException - Android
问题描述
我已经上传了我今天的Android应用程序市场,我接受了4个错误关于 NumberFormatException异常,Double.parseDouble
和 Double.valueOf
。
I've uploaded my Android app to the Market today, and I received 4 errors regarding NumberFormatException,Double.parseDouble
and Double.valueOf
.
下面是我的logcat在开发者控制台中看到:
Here's the Logcat I see in the Developer Console:
java.lang.RuntimeException: Unable to start activity ComponentInfo{can.you.drive/can.you.drive.do_drive}: java.lang.NumberFormatException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
at android.app.ActivityThread.access$1500(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4196)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException
at org.apache.harmony.luni.util.FloatingPointParser.parseDblImpl(Native Method)
at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:283)
at java.lang.Double.parseDouble(Double.java:318)
at java.lang.Double.valueOf(Double.java:356)
at can.you.drive.dont_drive.roundTwoDecimals(dont_drive.java:132)
at can.you.drive.do_drive.onCreate(do_drive.java:125)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
下面是其中的错误(根据日志)发生作用 -
Here's the function in which the error occurs(according to the Log) -
public static double roundTwoDecimals(double d) {
DecimalFormat twoDForm = new DecimalFormat("#.###");
return Double.valueOf(twoDForm.format(d));
}
我知道 D
加倍。
此外,该工作正常在我的手机(Nexus S的运行2.3.4)。我是从其他用户得到的错误。这就是为什么我真的不能调试。
Also, this works fine on my phone(Nexus S running 2.3.4). I'm getting the error from other users. That's why I can't really debug it.
我真的不知道我的这个原因在某些手机上。
I really don't know what my cause this on some phones.
推荐答案
我会说这是要做本地化,以。
不是在小数点分隔符发生错误的平台。你为什么不使用四舍五入的更便宜的方法是什么?
I'd say it's got to do with localization, with .
not being the decimal separator in the platforms where the error occurs. Why don't you use a less expensive method of rounding?
public double round(double d, int nDecimals)
{
for(int i=0; i<nDecimals; ++i) d *= 10d;
d=Math.round(d);
for(int i=0; i<nDecimals; ++i) d /= 10d;
return d;
}
这篇关于NumberFormatException - 如果机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!