samedi 30 janvier 2016

No such table SQLiteException [duplicate]

This question already has an answer here:

I have a pre-populated database containing one table that is located in my assets folder which I'm having trouble reading. All I want to do is a couple of SELECT queries on the database.

It was all previously working fine then I decided to add some more data to the .db file (I just used DB browser for SQLite to achieve this) ever since I added more data I get the error android.database.sqlite.SQLiteException: no such table: SOULS (code 1) even though the table SOULS exists and had previously worked fine. I see this error is fairly common but nothing I have looked up seems to help me.

Database:

enter image description here

Code:

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "BB2Database.db";
    private static final int DATABASE_VERSION = 2;
    public static final String TABLE_NAME = "SOULS";
    public static final String SOUL_COLUMN_THUMBNAIL = "thumbnail";
    public static final String SOUL_COLUMN_NAME = "name";
    public static final String SOUL_COLUMN_TYPE = "type";


    public DBHelper(Context context) {
        super(context, DATABASE_NAME , null, DATABASE_VERSION);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
    }

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

    public Cursor getItem(String id) {
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor res =  db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " +
                SOUL_COLUMN_NAME + "=?", new String[]{id});
        return res;
    }

    public Cursor getAllItems() {
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor res =  db.rawQuery( "SELECT * FROM " + TABLE_NAME, null );
        return res;
    }
}

Logcat:

> 01-31 10:16:32.209  12321-12321/com.delm959.daniel.bb2sng W/dalvikvm﹕ VFY: unable to resolve virtual method 395: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
01-31 10:16:32.209  12321-12321/com.delm959.daniel.bb2sng D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-31 10:16:32.209  12321-12321/com.delm959.daniel.bb2sng I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawableForDensity
01-31 10:16:32.209  12321-12321/com.delm959.daniel.bb2sng W/dalvikvm﹕ VFY: unable to resolve virtual method 397: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
01-31 10:16:32.209  12321-12321/com.delm959.daniel.bb2sng D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-31 10:16:32.339  12321-12321/com.delm959.daniel.bb2sng E/SQLiteLog﹕ (1) no such table: SOULS
01-31 10:16:32.339  12321-12321/com.delm959.daniel.bb2sng D/AndroidRuntime﹕ Shutting down VM
01-31 10:16:32.339  12321-12321/com.delm959.daniel.bb2sng W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x418eeda0)
01-31 10:16:32.349  12321-12321/com.delm959.daniel.bb2sng E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.delm959.daniel.bb2sng, PID: 12321
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.delm959.daniel.bb2sng/com.delm959.daniel.bb2sng.MainActivity}: android.database.sqlite.SQLiteException: no such table: SOULS (code 1): , while compiling: SELECT * FROM SOULS
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
            at android.app.ActivityThread.access$900(ActivityThread.java:161)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.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.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.database.sqlite.SQLiteException: no such table: SOULS (code 1): , while compiling: SELECT * FROM SOULS
            at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
            at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1121)
            at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:694)
            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:44)
            at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1436)
            at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1375)
            at com.delm959.daniel.bb2sng.DBHelper.getAllItems(DBHelper.java:39)
            at com.delm959.daniel.bb2sng.MainActivity.updateList(MainActivity.java:79)
            at com.delm959.daniel.bb2sng.MainActivity.onCreate(MainActivity.java:53)
            at android.app.Activity.performCreate(Activity.java:5426)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
            at android.app.ActivityThread.access$900(ActivityThread.java:161)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.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.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)
01-31 10:16:35.252  12321-12321/? I/Process﹕ Sending 

signal. PID: 12321 SIG: 9

Aucun commentaire:

Enregistrer un commentaire