Android下一个数据库异常得解决方法

来源:互联网 发布:长图截屏软件 编辑:程序博客网 时间:2024/06/14 18:59
查询数据库时报如下错误:
Caused by: android.database.sqlite.SQLiteException: no such column: ٤٧٤٣٦: , while compiling: select * from test where id=٤٧٤٣٦

以上错误异常是通过友盟异常组件抓取到得。
٤٧٤٣٦ 是阿拉伯语数字;

产生这个问题得原因是本地化问题,构造查询字符串是用String.format(...)函数,如果没有指定Locale缺省是系统缺省Locale;如果在汉语,英语等常用系统下没问题。在阿语系统下,数字和货币就会被本地化表示。

解决方法很简单:
String.format函数指定使用Locale为US.

String.format(Locale.US,...);