Android Studio Sqlite Import Error delete method

Asked

Viewed 96 times

0

Is not deleting table referring to database Android Studio points no error when clicking the button the program does nothing

(NA ACTIVITY Databasehelper) public void delete() {

    SQLiteDatabase db = getWritableDatabase();
    db.execSQL("DROP IF TABLE EXISTS mylist_data");
    onCreate(db);

}

(NA ACTIVITY Mainactivity) (On top) public class Mainactivity extends Appcompatactivity {

DatabaseHelper myDB;
Button button, button4, button2, button5;
EditText editText, editText2, editText3, editText4;

(Down at the time to call the metodo)

button2.setOnClickListener(new View.Onclicklistener() { @Override public void onClick(View v) {

        myDB.delete();
  • Did you refer to button2? button2 = findViewById(R.id.button2); I did not see in your code above.

1 answer

0

I didn’t test your code but looking at:

db.execSQL("DROP IF TABLE EXISTS mylist_data");

It looks like you are putting IF before TABLE.

The right thing would be:

db.execSQL("DROP TABLE IF EXISTS mylist_data");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.