我想使字符串值int显示为
所以我把这段代码放在我的Java类
中 DecimalFormat formatter = new DecimalFormat("###.###.###");
String get_value = formatter.format(aa);
a = (TextView)findViewById(R.id.ttn);
a.setText(String.valueOf(get_value));
DecimalFormat formatter2 = new DecimalFormat("###.###.###");
String get_value2 = formatter2.format(bb);
b = (TextView)findViewById(R.id.tfn);
b.setText(String.valueOf(get_value2));
但是当我把它运行到模拟器中时它是强制关闭的,这里是logcat
11-13 23:32:31.128: E/AndroidRuntime(700): FATAL EXCEPTION: main
11-13 23:32:31.128: E/AndroidRuntime(700): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.example/com.app.example.menu}: java.lang.IllegalArgumentException: ###.###.###
11-13 23:32:31.128: E/AndroidRuntime(700): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-13 23:32:31.128: E/AndroidRuntime(700): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-13 23:32:31.128: E/AndroidRuntime(700): at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-13 23:32:31.128: E/AndroidRuntime(700): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-13 23:32:31.128: E/AndroidRuntime(700): at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 23:32:31.128: E/AndroidRuntime(700): at android.os.Looper.loop(Looper.java:137)
11-13 23:32:31.128: E/AndroidRuntime(700): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-13 23:32:31.128: E/AndroidRuntime(700): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 23:32:31.128: E/AndroidRuntime(700): at java.lang.reflect.Method.invoke(Method.java:511)
11-13 23:32:31.128: E/AndroidRuntime(700): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-13 23:32:31.128: E/AndroidRuntime(700): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-13 23:32:31.128: E/AndroidRuntime(700): at dalvik.system.NativeStart.main(Native Method)
11-13 23:32:31.128: E/AndroidRuntime(700): Caused by: java.lang.IllegalArgumentException: ###.###.###
11-13 23:32:31.128: E/AndroidRuntime(700): at java.text.DecimalFormat.initNative(DecimalFormat.java:567)
11-13 23:32:31.128: E/AndroidRuntime(700): at java.text.DecimalFormat.<init>(DecimalFormat.java:560)
11-13 23:32:31.128: E/AndroidRuntime(700): at java.text.DecimalFormat.<init>(DecimalFormat.java:538)
11-13 23:32:31.128: E/AndroidRuntime(700): at com.app.example.menu.onCreate(menu.java:162)
11-13 23:32:31.128: E/AndroidRuntime(700): at android.app.Activity.performCreate(Activity.java:5008)
11-13 23:32:31.128: E/AndroidRuntime(700): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-13 23:32:31.128: E/AndroidRuntime(700): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-13 23:32:31.128: E/AndroidRuntime(700): ... 11 more
答案 0 :(得分:3)
阅读例外:
java.lang.IllegalArgumentException:###。###。###
现在看看你的模式,它对DecimalFormat无效,因为它有两个小数点......
使用分组分隔符(,
),您的语言环境会将其更改为a。在输出中,如果这是你的语言环境的配置。