无法在sqlite android中删除元素

时间:2011-02-24 13:36:00

标签: android

你好我今天一直在谷歌上搜索没有运气。问题是我正在尝试从我的数据库中删除一个元素,但我只得到02-24 14:04:32.635: ERROR/AndroidRuntime(8823): android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x327de0

数据库中的表只有一列INTEGER PRIMARY KEY,并且TRIGGER就像这样

CREATE TRIGGER "FavForeignKey" BEFORE INSERT ON Favorites WHEN (SELECT rowid FROM Sign Where Sign.rowid = NEW.ViewedImage) IS NULL  BEGIN       SELECT RAISE(ROLLBACK, 'insert on table "Favorites" violates foreign key constraint "Sign.rowid"'); END

我不知道为什么我会收到这个错误,我需要一些帮助。

**Here is the query i'm using:**

public void deleteFavorite(int imageId){
        m_db.delete(FAVORITE_TABLE, FAVORITES_COLUMN_VIEWED_IMAGE, new String[]{""+imageId});
    }

这是错误堆栈:

02-24 14:04:32.635: ERROR/AndroidRuntime(8823): android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x327de0
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at android.database.sqlite.SQLiteProgram.native_bind_string(Native Method)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:241)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at android.database.DatabaseUtils.bindObjectToProgram(DatabaseUtils.java:191)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1669)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at com.enea.takk.database.DBManager.deleteFavorite(DBManager.java:161)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at com.enea.takk.views.ShowImage$1.onClick(ShowImage.java:82)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at android.os.Looper.loop(Looper.java:144)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at android.app.ActivityThread.main(ActivityThread.java:4937)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at java.lang.reflect.Method.invokeNative(Native Method)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at java.lang.reflect.Method.invoke(Method.java:521)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-24 14:04:32.635: ERROR/AndroidRuntime(8823):     at dalvik.system.NativeStart.main(Native Method)

一些帮助将不胜感激。

提前致谢

1 个答案:

答案 0 :(得分:2)

试试这个

public void deleteFavorite(int imageId){ 
m_db.delete(FAVORITE_TABLE, FAVORITES_COLUMN_VIEWED_IMAGE + "=" +imageId,null); 
}