【发布时间】:2013-03-26 13:40:30
【问题描述】:
这是我的代码:
TextView headerVal = (TextView) nextChild.findViewById(R.id.textView3);
String tt = ((String)headerVal.getText()).replaceAll(",",""); //it was 1,000 and it became 1000
int longueur = tt.length();
String aux2 = (String) tt.substring(0,longueur - 2);
int contenu = (int) Integer.parseInt(aux2);// here is the error "unable to parse 1000 as an integer".
PS:它可以在模拟器上运行,但我在手机上遇到了这个错误
Logcat:
04-04 13:04:15.210: E/AndroidRuntime(31718): FATAL EXCEPTION: main
04-04 13:04:15.210: E/AndroidRuntime(31718): java.lang.NumberFormatException: unable to parse '1 000' as integer
04-04 13:04:15.210: E/AndroidRuntime(31718):at java.lang.Integer.parse(Integer.java:433)
04-04 13:04:15.210: E/AndroidRuntime(31718):at java.lang.Integer.parseInt(Integer.java:422)
04-04 13:04:15.210: E/AndroidRuntime(31718):at java.lang.Integer.parseInt(Integer.java:382)
04-04 13:04:15.210:E/AndroidRuntime(31718):at com.example.appui.BarGraphActivity.setColumnParts(BarGraphActivity.java:408)
04-04 13:04:15.210: E/AndroidRuntime(31718):at com.example.appui.BarGraphActivity.access$2(BarGraphActivity.java:282)
04-04 13:04:15.210: E/AndroidRuntime(31718):at com.example.appui.BarGraphActivity$Desired_pension.onStopTrackingTouch(BarGraphActivity.java:162)
【问题讨论】:
-
它显示了什么??任何错误??
-
无法将 1000 解析为整数
-
@Sebastian 不明白你的想法,请详细说明
-
可能是trimming的问题
-
为什么在 Integer 解析值后在最后一条语句中类型转换 'int' ?