-1

It was giving that after pressing delete button. Start button was working well.Any help please When running this sample of code on AVD, It was giving "App has stopped". Is my way to delete the database it self. Please suggest other ideas.

package com.example.nbe;

import java.io.File;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

private static final String debug = null;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    db = openOrCreateDatabase("NBE_name",MODE_PRIVATE,null);
    Log.d(debug, "Database Created");

    // Start App
    Button start = (Button) findViewById(R.id.start);
    start.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(MainActivity.this, "hello!!! =)", Toast.LENGTH_LONG).show();
            db.execSQL("CREATE TABLE IF NOT EXISTS NBE_table(Username VARCHAR,Password VARCHAR);");
            db.execSQL("INSERT INTO NBE_table VALUES('admin','admin');");
            Log.d(debug, "Table Created");
        }
    });

Button del = (Button)findViewById(R.id.delete);
    del.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            SQLiteDatabase.deleteDatabase(new File("data/data/com.example.name/database/NBE_name"));
        }
    });
}




}

1 Answers1

0

If you want to delete your database, you can use this:

context.deleteDatabase(DB_NAME); //DB_NAME is a String
SuperFrog
  • 7,631
  • 9
  • 51
  • 81