我有大约50台设备在运行我的应用程序。有些用户会遇到一个奇怪的错误(并非全部):
android.database.sqlite.SQLiteException: no such table: points (code 1)
at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method)
at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:840)
at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:836)
at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:197)
at android.database.AbstractCursor.moveToNext(AbstractCursor.java:245)
at kgk_logic.Manager.reloadPoints(Manager.java:67)
at mobile.WorkActivity$WHandler.handleMessage(WorkActivity.java:544)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5124)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:783)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:550)
at dalvik.system.NativeStart.main(Native Method)
逻辑是:一旦在15分钟内设备检查其位置并与远程bd数据进行比较/如果特定半径的设备 - 服务器返回一个点列表(只是坐标)。这些点转到SQLTable“点”,但在此之前删除了previus points表,并使用新的新数据创建了新表:
DB db = DB.getInstance(KGKMobile.getAppContext());
SQLiteDatabase wdb = db.getWritableDatabase();
wdb.execSQL(String.format("DROP TABLE %s", DB.POINTS_TABLE));
db.createPointsTable(wdb);
for (KGKPoint point : WorkActivity.getManager().getPoints()) {
wdb.insert(DB.POINTS_TABLE, null, point.getCV());
}
方法createPointsTable()
只包含一个查询:
execSQL(String.format("CREATE TABLE %s (id integer PRIMARY KEY NOT NULL, name TEXT NOT NULL, lat real NOT NULL, lng real NOT NULL, code TEXT )", "points"));
我的赌注 - 桌子掉了但没有正确创建。但我不知道为什么。或许还有另一个原因?