SQLiteDatabase getWritableDatabase(){抛出新的RuntimeException("存根"!); } [英] SQLiteDatabase getWritableDatabase() { throw new RuntimeException("Stub!"); }

查看:183
本文介绍了SQLiteDatabase getWritableDatabase(){抛出新的RuntimeException("存根"!); }的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试运行的getItem()的方法

公共类PhoneDal扩展SQLiteOpenHelper {

public class PhoneDal extends SQLiteOpenHelper {

// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = Constants.DB_NAME;

private static final String BLOCKED_PHONES_TABLE = "BLOCKED_PHONES_TABLE";
private static final String COMMENTS_TABLE = "COMMENTS_TABLE";

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

@Override
public void onCreate(SQLiteDatabase db) {
    // SQL statement to create book table

    String CREATE_BLOCKED_PHONES_TABLE = "CREATE TABLE "
            + BLOCKED_PHONES_TABLE + " ( "
            + KEY_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_PHONE+" TEXT, "
            + KEY_IS_BLOCKED+" BIT )";

    db.execSQL(CREATE_BLOCKED_PHONES_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    if (newVersion > oldVersion) {
        Log.w("MyAppTag", "Updating database from version " + oldVersion
                + " to " + newVersion + " .Existing data will be lost.");
        // Drop older books table if existed
        db.execSQL("DROP TABLE IF EXISTS " + BLOCKED_PHONES_TABLE);

        // create fresh books table
        this.onCreate(db);
    }

}



private static final String KEY_ID = "id";
private static final String KEY_PHONE = "KEY_PHONE";
private static final String KEY_IS_BLOCKED = "KEY_IS_BLOCKED";

public Phone getItem(String phone) {
    Phone result = new Phone();

    Cursor cursor = this.getReadableDatabase().query(BLOCKED_PHONES_TABLE,
            new String[] { KEY_ID  }, ""+KEY_PHONE+" = ? AND "+KEY_IS_BLOCKED+" = ?",
            new String[] { phone, "1" }, null, null, null);

    // 3. if we got results get the first one
    if (cursor != null) {
        result.id = (cursor.getInt(1));
        result.phone = phone;
        result.isBlocked = false;
    }
    return result;
}

我得到这个异​​常:

I get this exception:

Process: com.example.stopcall.app, PID: 31146
android.database.sqlite.SQLiteException: no such column: KEY_PHONE (code 1): , while compiling: SELECT id FROM BLOCKED_PHONES_TABLE WHERE KEY_PHONE = ? AND KEY_IS_BLOCKED = ?
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:690)
        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:1448)
        at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1295)
        at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1166)
        at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1334)
        at com.example.stopcall.app.dal.PhoneDal.getItem(PhoneDal.java:117)
        at com.example.stopcall.app.ItemDetailFragment$1.onClick(ItemDetailFragment.java:93)
        at android.view.View.performClick(View.java:4654)
        at android.view.View$PerformClick.run(View.java:19438)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:146)
        at android.app.ActivityThread.main(ActivityThread.java:5602)
        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:1283)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
        at dalvik.system.NativeStart.main(Native Method)

为什么我看到:

why do I see that:

public void setWriteAheadLoggingEnabled(boolean enabled) {
    throw new RuntimeException("Stub!");
}

public SQLiteDatabase getWritableDatabase() {
    throw new RuntimeException("Stub!");
}

public SQLiteDatabase getReadableDatabase() {
    throw new RuntimeException("Stub!");
}

在code送过来每次

the code gets here every time

推荐答案

您正在寻找的的android.jar 文件的反编译的版本,而不是实际的Andr​​oid $ C一个设备或模拟器上运行$ C。

You are looking at a decompiled version of the android.jar file, not the actual Android code that runs on a device or emulator.

对于实际的问题,我的猜测是,你改变了你的数据库模式不改变(在你的code DATABASE_VERSION )的架构版本。无论是增量 DATABASE_VERSION 和实施的OnUpdate(),或者卸载并重新安装应用程序,以摆脱你的旧数据库。

With respect to the actual problem, my guess is that you changed your database schema without changing the schema version (DATABASE_VERSION in your code). Either increment DATABASE_VERSION and implement onUpdate(), or uninstall and reinstall your app to get rid of your old database.

这篇关于SQLiteDatabase getWritableDatabase(){抛出新的RuntimeException(&QUOT;存根&QUOT;!); }的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆