Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 应用程序可以在模拟器上工作,但不能在真正的设备-浮点型上工作_Android - Fatal编程技术网

Android 应用程序可以在模拟器上工作,但不能在真正的设备-浮点型上工作

Android 应用程序可以在模拟器上工作,但不能在真正的设备-浮点型上工作,android,Android,我的应用程序在使用仿真器时运行良好,但在实际设备上运行时崩溃。我为Android 2.2编写了代码。真正的设备是2.3.6 问题就在这里: 当我使用这样的东西时: tvPlayerOneScores.setText("-" + numberFormat.format(level)); 它在模拟器和真实设备上都非常有效 但当我尝试这个: tvPlayerOneScores.setText("-" + numberFormat.format(level * 0.5f)); 它在模拟器上工作,但在

我的应用程序在使用仿真器时运行良好,但在实际设备上运行时崩溃。我为Android 2.2编写了代码。真正的设备是2.3.6

问题就在这里:

当我使用这样的东西时:

tvPlayerOneScores.setText("-" + numberFormat.format(level));
它在模拟器和真实设备上都非常有效

但当我尝试这个:

tvPlayerOneScores.setText("-" + numberFormat.format(level * 0.5f));
它在模拟器上工作,但在真实设备上崩溃

堆栈跟踪:

java.lang.NumberFormatException
    at org.apache.harmony.luni.util.FloatingPointParser.parseFltImpl(Native Method)
    at org.apache.harmony.luni.util.FloatingPointParser.parseFloat(FloatingPointParser.java:321)
    at java.lang.Float.parseFloat(Float.java:323)
    at java.lang.Float.valueOf(Float.java:362)
    at com.amrotek.truthordare.GameActivity$4.onClick(GameActivity.java:287)
    at android.view.View.performClick(View.java:2552)
    at android.view.View$PerformClick.run(View.java:9229)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3701)
    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:866)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
    at dalvik.system.NativeStart.main(Native Method)
编辑:
我将所有的值乘以10,所以我在做算术运算时只处理整数。在最后,我只需将结束值除以10。有效:)

您应该在问题中包括故障线路,而不是在注释中:

playerOnePoints = Float.valueOf(numberFormat.format(playerOnePoints - level * 0.5f));
由于这还不足以得出结论,这里有一个简短的清单供您检查:

  • 为什么您需要用
    numberFormat
    格式化一个数字,然后用
    valueOf
    将其转换回来

  • 什么是
    numberFormat
    ,它真的会产生有效的浮点字符串吗

  • 是浮动还是浮动?您是否应该使用
    parseFloat()
    而不是
    valueOf()

  • 最后,如果您仍然无法解决您的问题,我建议将上述行替换为simple:

    playerOnePoints = playerOnePoints - level * 0.5f;
    
    这就应该奏效了


    另外,如果我正确理解了你的意图,你可能还想了解一下
    Math.floor()/ceil()

    你应该在问题中包括错误的行,而不是在评论中:

    playerOnePoints = Float.valueOf(numberFormat.format(playerOnePoints - level * 0.5f));
    
    由于这还不足以得出结论,这里有一个简短的清单供您检查:

  • 为什么您需要用
    numberFormat
    格式化一个数字,然后用
    valueOf
    将其转换回来

  • 什么是
    numberFormat
    ,它真的会产生有效的浮点字符串吗

  • 是浮动还是浮动?您是否应该使用
    parseFloat()
    而不是
    valueOf()

  • 最后,如果您仍然无法解决您的问题,我建议将上述行替换为simple:

    playerOnePoints = playerOnePoints - level * 0.5f;
    
    这就应该奏效了


    另外,如果我正确地理解了你的意图,你可能还想熟悉一下
    Math.floor()/ceil()

    你有什么例外?发布crashYep的堆栈跟踪,需要像raghav提到的那样的堆栈跟踪,哪一行是GameActivity.java:287?@m0skit0第287行:
    playerPoints=Float.valueOf(numberFormat.format(playerPoints-level*0.5f))很遗憾,有了这些信息,我们无法帮助您。这实际上没有告诉我们任何关于价值观的信息。你调试过了吗?有什么异常?发布crashYep的堆栈跟踪,需要像raghav提到的那样的堆栈跟踪,哪一行是GameActivity.java:287?@m0skit0第287行:
    playerPoints=Float.valueOf(numberFormat.format(playerPoints-level*0.5f))很遗憾,有了这些信息,我们无法帮助您。这实际上没有告诉我们任何关于价值观的信息。你调试过了吗?