在sqlite表中插入int值时出错

时间:2018-02-21 11:08:46

标签: android android-sqlite

当我在我的sqlite中插入int值时,它会一直说回false

这是我的onCreate方法

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("create table PicTable(id INTEGER PRIMARY KEY AUTOINCREMENT,pic_key INTEGER)");
}

这是检查插入

的方法
 public boolean insertPic (int pic){
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put("pic_key",pic);
    long result = db.insert("PicTable",null,contentValues);
    if (result == -1)
        return false;
    else
        return true;

}

当我输入int值时,它会返回false

我的代码或其他内容是否有错误?

这是我的logcat

02-21 03:14:35.916 4507-4507/com.example.android.durak E/SQLiteDatabase: Error inserting pic_key=1
                                                                         android.database.sqlite.SQLiteException: no such table: PicTable (code 1): , while compiling: INSERT INTO PicTable(pic_key) VALUES (?)
                                                                             at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                                                                             at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
                                                                             at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
                                                                             at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                                                                             at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
                                                                             at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
                                                                             at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
                                                                             at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
                                                                             at com.example.android.durak.sql_lite.insertPic(sql_lite.java:64)
                                                                             at com.example.android.durak.Option.Save(Option.java:33)
                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                             at java.lang.reflect.Method.invoke(Method.java:372)
                                                                             at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
                                                                             at android.view.View.performClick(View.java:4780)
                                                                             at android.view.View$PerformClick.run(View.java:19866)
                                                                             at android.os.Handler.handleCallback(Handler.java:739)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                             at android.os.Looper.loop(Looper.java:135)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                             at java.lang.reflect.Method.invoke(Method.java:372)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

0 个答案:

没有答案