尝试从ListView和数据库中删除项目时出现此错误,我该如何解决?谢谢这是方法:
public int deleteSelectedItem(String number) {
SQLiteDatabase db = this.getWritableDatabase();
int result = db.delete( DB_TABLE, "number = ?", new String[] {number} );
return result;
}
这是电话:
userlist.setOnItemLongClickListener( new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick (AdapterView<?> arg0, View view, final int position, long arg3) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder( MainActivity.this );
alertDialog.setTitle( "Elimina" );
alertDialog.setMessage( listItem.get( position ) );
alertDialog.setPositiveButton( "Elimina", new DialogInterface.OnClickListener() {
@Override
public void onClick (DialogInterface dialog, int which) {
db.deleteSelectedItem( listItem.get( position ) );
}
} );
alertDialog.show();
return true;
}
} );
Logcat:
android.database.sqlite.SQLiteException: no such column: number (code 1): , while compiling: DELETE FROM Users_Table WHERE number = ?
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
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.delete(SQLiteDatabase.java:1496)
at com.example.listviewsqlite.DatabaseHelper.deleteSelectedItem(DatabaseHelper.java:54)
at com.example.listviewsqlite.MainActivity$2$1.onClick(MainActivity.java:68)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:163)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
谢谢!有了您的帮助,我解决了! :)