有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android SQLite DB表,仅在某些设备上没有此类表错误

我已经翻遍了档案,试图找到一个解决我的问题的办法,但似乎都是无关的。自从我首次发布应用程序以来,我对数据库进行了一些升级,包括添加了2个新表。在我的最新版本发布后,我收到了多个bug报告,指出“没有这样的表”存在,而我知道它存在。我无法在我的任何个人设备上重新创建报告的错误,我不确定我可以更改什么。 下面是我收到的错误以及创建和升级DB表的DB Helper类的副本

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.skylandersdb/com.skylandersdb.CharacterDetailActivity}: 安卓.database.sqlite.SQLiteException: no such table: tblCollectorGroups (code 1): , while compiling: SELECT collectName FROM tblCollectorGroups
at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at 安卓.app.ActivityThread.access$900(ActivityThread.java:161)
at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at 安卓.os.Handler.dispatchMessage(Handler.java:102)
at 安卓.os.Looper.loop(Looper.java:157)
at 安卓.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: 安卓.database.sqlite.SQLiteException: no such table: tblCollectorGroups (code 1): , while compiling: SELECT collectName FROM tblCollectorGroups
at 安卓.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at 安卓.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
at 安卓.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:690)
at 安卓.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at 安卓.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at 安卓.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at 安卓.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at 安卓.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1430)
at 安卓.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1369)
at com.skylandersdb.CharacterDetailActivity.getListCollectorGroup(CharacterDetailActivity.java:925)
at com.skylandersdb.CharacterDetailActivity.loadCollectorGroup(CharacterDetailActivity.java:908)
at com.skylandersdb.CharacterDetailActivity.onCreate(CharacterDetailActivity.java:400)
at 安卓.app.Activity.performCreate(Activity.java:5426)
at 安卓.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
... 11 more`

这是我的DBHelper类,我在其中创建和升级我的db

   import 安卓.content.Context;
   import 安卓.database.sqlite.SQLiteDatabase;
   import 安卓.database.sqlite.SQLiteOpenHelper;
   import 安卓.provider.BaseColumns;
   import 安卓.util.Log;

    public class DBHelper_Skylanders extends SQLiteOpenHelper {

private static final String TAG = DBHelper_Skylanders.class.getSimpleName();

public static final String DB_NAME = "skylandersDB";
public static final int DB_VERSION = 6;

public static final String TABLE_skylanders = "tblSkylanders";
public static final String C_ID = BaseColumns._ID;
public static final String C_skyid = "skyid";
public static final String C_depth = "depth";
public static final String C_preName = "preName";
public static final String C_mainName = "mainName";
public static final String C_descName = "descName";
public static final String C_element = "element";
public static final String C_figureType = "figureType";
public static final String C_pic = "pic";
public static final String C_primePower = "primePower";
public static final String C_noOfFigures = "noOfFigures";
public static final String C_game = "game";
public static final String C_attackStat = "attackStat";
public static final String C_attackBase = "attackBase";
public static final String C_agilityStat = "agilityStat";
public static final String C_agilityBase = "agilityBase";
public static final String C_defenseStat = "defenseStat";
public static final String C_defenseBase = "defenseBase";
public static final String C_luckStat = "luckStat";
public static final String C_luckBase = "luckBase";
public static final String C_origin = "origin";
public static final String C_phrase = "phrase";

public static final String TABLE_cGroups = "tblCollectorGroups";
public static final String C_cGroupName = "collectName";
public static final String C_cGroup1 = "collection1";
public static final String C_cGroup2 = "collection2";
public static final String C_cGroup3 = "collection3";

public static final String TABLE_collect = "tblCollection";
public static final String C_skylanderid = "skylanderID";
public static final String C_collectid = "collectid";
public static final String C_collectName = "collectName";
public static final String C_collection = "collection";

public String sql = null;

public final Context myContext;

public DBHelper_Skylanders(Context context) {
    super(context, DB_NAME, null, DB_VERSION);
    this.myContext = context;
}


@Override
public void onCreate(SQLiteDatabase db) {
    sql = String.format("create table %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s INTEGER, %s INTEGER, %s TEXT, %s TEXT, %s TEXT, %s TEXT, %s TEXT, %s INTEGER,  %s INTEGER, %s INTEGER, %s TEXT, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s TEXT, %s TEXT, %s TEXT)", 
            TABLE_skylanders, C_ID, C_skyid, C_depth, C_preName, C_mainName, C_descName, C_element, C_figureType, C_pic, C_primePower, C_noOfFigures, C_game, C_attackStat, C_attackBase, C_agilityStat, C_agilityBase, C_defenseStat, C_defenseBase, C_luckStat, C_luckBase, C_origin, C_phrase, C_collection);
    //test script
    Log.d(TAG, "onCreate sql: "+sql);
    //executes SQL statement
    db.execSQL(sql);
    sql = null;

    sql = String.format("create table %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s TEXT, %s TEXT, %s TEXT, %s TEXT)", 
            TABLE_cGroups, C_ID, C_cGroupName, C_cGroup1, C_cGroup2, C_cGroup3);
    //test script
    Log.d(TAG, "onCreate sql: "+sql);
    //executes SQL statement
    db.execSQL(sql);
    sql = null;

    sql = String.format("create table %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s INTEGER, %s INTEGER, %s TEXT, %s TEXT)", 
            TABLE_collect, C_ID, C_skylanderid, C_collectid, C_collectName, C_collection);
    //test script
    Log.d(TAG, "onCreate sql: "+sql);
    //executes SQL statement
    db.execSQL(sql);
    sql = null;
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    switch(oldVersion)
    {
        case 3:
            db.execSQL("drop table if exists " + TABLE_skylanders);
            Log.d(TAG, "onUpdate dropped table " + TABLE_skylanders);

            db.execSQL("drop table if exists " + TABLE_cGroups);
            Log.d(TAG, "onUpdate dropped table " + TABLE_cGroups);

            db.execSQL("drop table if exists " + TABLE_collect);
            Log.d(TAG, "onUpdate dropped table " + TABLE_collect);

            onCreate(db);

        case 4:
            //only drops tblSkylander
            db.execSQL("drop table if exists " + TABLE_skylanders);
            Log.d(TAG, "onUpdate dropped table " + TABLE_skylanders);

            //only recreates tblSkylander
            sql = String.format("create table %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s INTEGER, %s INTEGER, %s TEXT, %s TEXT, %s TEXT, %s TEXT, %s TEXT, %s INTEGER,  %s INTEGER, %s INTEGER, %s TEXT, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s TEXT, %s TEXT, %s TEXT)", 
                    TABLE_skylanders, C_ID, C_skyid, C_depth, C_preName, C_mainName, C_descName, C_element, C_figureType, C_pic, C_primePower, C_noOfFigures, C_game, C_attackStat, C_attackBase, C_agilityStat, C_agilityBase, C_defenseStat, C_defenseBase, C_luckStat, C_luckBase, C_origin, C_phrase, C_collection);
            Log.d(TAG, "onCreate sql: "+sql);
            db.execSQL(sql);

            sql = String.format("create table if not exists %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s TEXT, %s TEXT, %s TEXT, %s TEXT)", 
                    TABLE_cGroups, C_ID, C_cGroupName, C_cGroup1, C_cGroup2, C_cGroup3);
            //test script
            Log.d(TAG, "onCreate sql: "+sql);
            //executes SQL statement
            db.execSQL(sql);

            sql = String.format("create table if not exists %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s INTEGER, %s INTEGER, %s TEXT, %s TEXT)", 
                    TABLE_collect, C_ID, C_skylanderid, C_collectid, C_collectName, C_collection);
            //test script
            Log.d(TAG, "onCreate sql: "+sql);
            //executes SQL statement
            db.execSQL(sql);

        case 5:
            //only drops tblSkylander
            db.execSQL("drop table if exists " + TABLE_skylanders);
            Log.d(TAG, "onUpdate dropped table " + TABLE_skylanders);

            //only recreates tblSkylander
            sql = String.format("create table %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s INTEGER, %s INTEGER, %s TEXT, %s TEXT, %s TEXT, %s TEXT, %s TEXT, %s INTEGER,  %s INTEGER, %s INTEGER, %s TEXT, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s INTEGER, %s TEXT, %s TEXT, %s TEXT)", 
                    TABLE_skylanders, C_ID, C_skyid, C_depth, C_preName, C_mainName, C_descName, C_element, C_figureType, C_pic, C_primePower, C_noOfFigures, C_game, C_attackStat, C_attackBase, C_agilityStat, C_agilityBase, C_defenseStat, C_defenseBase, C_luckStat, C_luckBase, C_origin, C_phrase, C_collection);
            Log.d(TAG, "onCreate sql: "+sql);
            db.execSQL(sql);

            sql = String.format("create table if not exists %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s TEXT, %s TEXT, %s TEXT, %s TEXT)", 
                    TABLE_cGroups, C_ID, C_cGroupName, C_cGroup1, C_cGroup2, C_cGroup3);
            Log.d(TAG, "onCreate sql: "+sql);
            db.execSQL(sql);

            sql = String.format("create table if not exists %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s INTEGER, %s INTEGER, %s TEXT, %s TEXT)", 
                    TABLE_collect, C_ID, C_skylanderid, C_collectid, C_collectName, C_collection);
            Log.d(TAG, "onCreate sql: "+sql);
            db.execSQL(sql);
    }   

}

}


共 (0) 个答案