我使用以下代码:
private static final String JUMP_COUNT_QUERY_FORMAT =
"select count(*) " +
"from log_entry " +
"inner join log_entry_rig on log_entry._id = log_entry_rig.log_entry " +
"where log_entry_rig.rig = {0}"; //TODO BUG crash in arabic
然后再说:
String query = MessageFormat.format(JUMP_COUNT_QUERY_FORMAT, rigId);
Cursor cursor = null;
try
{
cursor = db.rawQuery(query, null);
...
}
导致stacktrace中出现此错误,您可以在其中看到rigId中的1变为阿拉伯语1(1):
E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.myapp, PID: 4913
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.myapp/org.myapp.appLog2}: android.database.sqlite.SQLiteException: no such column: ١ (code 1 SQLITE_ERROR): , while compiling: select count(*) from log_entry inner join log_entry_rig on log_entry._id = log_entry_rig.log_entry where log_entry_rig.rig = ١
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2925)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
Caused by: android.database.sqlite.SQLiteException: no such column: ١ (code 1 SQLITE_ERROR): , while compiling: select count(*) from log_entry inner join log_entry_rig on log_entry._id = log_entry_rig.log_entry where log_entry_rig.rig = ١
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:901)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:512)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:46)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1408)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1347)
现在,我知道MessageFormat并没有真正用于语言环境,但我在整个应用程序中有很多调用SQLite,我想要证明它可以防止崩溃这样的崩溃,如果它在包含不同数字系统的语言环境的设备上调用(阿拉伯语,泰语等...)。在这方面可以做些什么?