I'm doing a database program. I would like to have the option of deleting a database from database SQLite . So I did the following:
In my OpenHelper
I called the following method:
public void delete (){
SQLiteDatabase db = getWritableDatabase();
db.execSQL("DELETE FROM CLIENTE");
db.close();
}
Where CLIENT is the name of my table. So I created the method:
public void deletar (View view){
Dados_familiaOpenHelper dados_familiaOpenHelper = new Dados_familiaOpenHelper(null);
dados_familiaOpenHelper.delete();
}
This method is in a activity
that contains a button. This button fires onClick
and redirects to this method.
Okay. When I run my program, and I click the button, the app closes. Anyone have any advice or anything that can help me?
@EDIT
My OpenHelper class:
public class Dados_familiaOpenHelper extends SQLiteOpenHelper {
public Dados_familiaOpenHelper(Context context){
super(context, "Dados_familia", null, 4);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(ScriptDLL.getCreateTableCliente() );
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public void delete (){
SQLiteDatabase db = getWritableDatabase();
db.execSQL("DELETE FROM CLIENTE");
db.close();
}