This question already has answers here:
Unfortunately MyApp has stopped. How can I solve this?
(23 answers)
Closed 5 years ago.
There goes the code . I just cant figure out what is the problem. I am just taking the email and password as input from user and trying to store into a table named stu. The application crashes on clicking the sign in button which redirects to a next page using "intent" and inserting values into a table.
It would be of great help if problem could be identified that cause app to crash .
Thanks
Database Helper.java
package com.example.zain.smd1;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DB_NAME = "student.db";
public static final String Table_name = "stu";
public static final String COL1 = "Id";
public static final String COL2 = "EMAIL";
public static final String COL3 = "PASS";
private static final String PASS = "PASS";
private static final String EMAIL = "EMAIL";
public DatabaseHelper(Context context) {
super(context,DB_NAME,null,1);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + Table_name + " (Id INTEGER PRIMARY KEY AUTOINCREMENT, EMAIL TEXT , PASS TEXT)");
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+Table_name);
onCreate(db);
}
public boolean insertdata(String email , String pass){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues content = new ContentValues();
content.put(EMAIL,email);
content.put(PASS,pass);
long result = db.insert(Table_name,null,content);
if (result==-1){
return false;
}
else
return true;
}
}
Main Activity.java
package com.example.zain.smd1;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.preference.PreferenceManager;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText et1,et2;
String email,pass;
RelativeLayout r1;
SharedPreferences sp;
DatabaseHelper db;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1= (EditText) findViewById(R.id.eTemail);
et2 = (EditText) findViewById(R.id.eTpassword);
r1 = (RelativeLayout) findViewById(R.id.colorChange);
}
public void login(View view){
email = et1.getText().toString();
pass = et2.getText().toString();
if(email.equals("admin")&& pass.equals("admin")){
Toast.makeText(getApplicationContext(),
"Redirecting...",Toast.LENGTH_SHORT).show();
r1.setBackgroundColor(Color.RED);
/*sp= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor e= sp.edit();
e.putString("name",email);
e.putString("password",pass);
e.apply();*/
boolean ischecked = db.insertdata(et1.getText().toString(),et2.getText().toString());
if(ischecked==true) {
Toast.makeText(getApplicationContext(),
"Added",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, Main2Activity.class);
startActivity(intent);
}
}
else {
r1.setBackgroundColor(Color.GREEN);
Toast.makeText(getApplicationContext(),
"Invalid password or email",Toast.LENGTH_SHORT).show();
}
/*
String name=sp.getString("name","");
String pass= sp.getString("password","");
et1.setText(name);
et2.setText(pass);
*/
}
}
Application crashes on inserting into SQLite database . I just couldn't figure out whats wrong
Try to uninstall the existing application from your Debugging device and then install it again. Sometimes when you change the structure of your table after installing it and again you are installing then it doesn't create new table.
you should try this...
DatabaseHelper db;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//add this line in your code..
db = new DatabaseHelper(this);
et1= (EditText) findViewById(R.id.eTemail);
et2 = (EditText) findViewById(R.id.eTpassword);
r1 = (RelativeLayout) findViewById(R.id.colorChange);
}
Related
I'm new at the android studio. I tried creating SQLite Database but when I try inserting data android studio cannot resolve it. i also tried MainActivity.this and getApplicationContext instead of db=new DatabaseHelper(this); on this line. and on device monitor, it isn't creating a database file
MainActivity.java
package com.example.lenovo.sqlite_2_deneme;
import android.content.Context;
import android.media.midi.MidiDevice;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
DatabaseHelper db;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db=new DatabaseHelper(this);
EditText et_name,et_surname,et_number;
Button btn_data;
et_name= (EditText) findViewById(R.id.et_isim);
et_surname= (EditText) findViewById(R.id.et_soyisim);
et_number= (EditText) findViewById(R.id.et_numara);
btn_data= (Button) findViewById(R.id.btn_veri);
btn_data.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
db.insertData();
}
});
}
}
and my DatabaseHelper class
package com.example.lenovo.sqlite_2_deneme;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.ContactsContract;
import android.widget.TableLayout;
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME= "student_info.db";
public static final String TABLE_NAME="student_table";
public static final String COL_1="ID";
public static final String COL_2="NAME";
public static final String COL_3="SURNAME";
public static final String COL_4="NUMBER";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE"+ TABLE_NAME+"(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, SURNAME TEXT, NUMBER INTEGER)");
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS"+ TABLE_NAME);
this.onCreate(db);
}
public Boolean DataInsert(String name, String surname, String number)
{
SQLiteDatabase db=this.getWritableDatabase();
ContentValues contentValues=new ContentValues();
contentValues.put(COL_2,name);
contentValues.put(COL_3,surname);
contentValues.put(COL_4,number);
long sonuc= db.insert(TABLE_NAME,null,contentValues);
if(sonuc==-1)
return false;
else
return true;
}
}
Your database will be created at the instance when you call
SQLiteDatabase db=this.getWritableDatabase();
At the moment I dont see you have called this anywhere in your code. You have written a DataInsert method but it is not getting called in the code you have shared so far.
your'e sql query is wrong give the space in table (insert data),and also in onupgrade and there is no method insertData()
db.execSQL("CREATE TABLE "+ TABLE_NAME+"(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, SURNAME TEXT, NUMBER INTEGER)");
There is no method insertData() . You should use
DataInsert() method .
db=new DatabaseHelper(MainActivity.this);
EditText et_name,et_surname,et_number;
Button btn_data;
et_name= (EditText) findViewById(R.id.et_isim);
et_surname= (EditText) findViewById(R.id.et_soyisim);
et_number= (EditText) findViewById(R.id.et_numara);
btn_data= (Button) findViewById(R.id.btn_veri);
btn_data.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
db.DataInsert(et_name.getText().toString(),et_surname.getText().toString(),et_number.getText().toString());
}
});
FYI
void onCreate (SQLiteDatabase db)
Called when the database is created for the first time.
This question already has answers here:
Unfortunately MyApp has stopped. How can I solve this?
(23 answers)
Closed 7 years ago.
I have this problem: I wrote an app, but the SQLiteDatabase isn't working.
My database class code:
package com.example.frauprinzssapp;
import android.content.ContentValues;
import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class database extends SQLiteOpenHelper{
public static final String DB_NAME = "users.db";
public static final String DB_TABLENAME = "users_table";
public static final String COL_1 = "id";
public static final String COL_2 = "name";
public static final String COl_3 = "class";
public static final String COL_4 = "right";
public database(Context context) {
super(context, DB_NAME, null, 1);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table "+DB_TABLENAME+"(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, class TEXT, right INTEGER)");
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXIST "+DB_TABLENAME);
onCreate(db);
}
public boolean insertdata(String name, String clas){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(COL_2, name);
cv.put(COl_3, clas);
cv.put(COL_4, 0);
long result = db.insert(DB_TABLENAME, null, cv);
if (result == -1){
return false;
}else{
return true;
}
}
}
The main code is:
package com.example.frauprinzssapp;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class Main extends Activity {
List<String> addusers = new ArrayList<String>();
database myDb;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myDb = new database(this);
}
//-----change view voids-----
public void main(View view){
setContentView(R.layout.main);
}
public void adduser(View view){
setContentView(R.layout.adduser);
}
public void removeuser(View view){
setContentView(R.layout.removeuser);
}
//------actions------
public void add(){
EditText name = (EditText) findViewById(R.id.aun);
EditText clas = (EditText) findViewById(R.id.auc);
if (name.toString() == null || clas.toString() == null){
Toast.makeText(Main.this, "please fill in all textfields!", Toast.LENGTH_LONG);
return;
}
try{
myDb.insertdata(name.toString(), clas.toString());
Toast.makeText(Main.this, "added user "+name.toString()+"!", Toast.LENGTH_LONG);
}catch(Exception e){
Toast.makeText(Main.this, "[ERROR] Could not create user maybe its already created!", Toast.LENGTH_LONG);
}
}
public void remove(){
}
public void show(){
}
}
I used the
android:onClick="add"
to make so that the add() void runs
please now it just puts random stuff into the sqlite pleaseeeee help
try it....
//------actions------
public void add(){
EditText name = (EditText) findViewById(R.id.aun);
EditText clas = (EditText) findViewById(R.id.auc);
String name1 = name.getText().toString();
String clas1 = clas.getText().toString();
if (name1.equals("") || clas1.equals("")){
Toast.makeText(Main.this, "please fill in all textfields!", Toast.LENGTH_LONG);
return;
}
try{
myDb.insertdata(name1, clas1);
Toast.makeText(Main.this, "added user "+name1+"!", Toast.LENGTH_LONG);
}catch(Exception e){
Toast.makeText(Main.this, "[ERROR] Could not create user maybe its already created!", Toast.LENGTH_LONG);
}
}
Im following a tutorial I want to insert a row into table while doing this Its run time fatal exception while inserting a row into database
Its Helper database class:
DatabasaeAdaptor.java
package com.example.sarahn.inserttable;
import android.content.ContentValues;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseAdaptor {
Helperdb helperdb;
DatabaseAdaptor(Context context){
helperdb = new Helperdb(context);
}
public long insertdata(String name,String password){
SQLiteDatabase db = helperdb.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(helperdb.NAME,name);
contentValues.put(helperdb.PASSWORD,password);
long id = db.insert(helperdb.TABLE_NAME,null,contentValues);
return id;
}
static class Helperdb extends SQLiteOpenHelper
{
private static final String DATABASE_NAME = "insert";
private static final String TABLE_NAME = "table";
private static final int DATABASE_VERSION = 1;
private static final String UID = "_name";
private static final String NAME = "user";
private static final String PASSWORD = "pw";
private static final String CREATE_TABLE = "CREATE TABLE
"+TABLE_NAME+"("+UID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+NAME+"
VARCHAR(255), "+PASSWORD+" VARCHAR(255));";
private static final String DROP_TABLE = "DROP TABLE IF EXISTS"
+TABLE_NAME;
private Context context;
//context, database name,
public Helperdb (Context context) {
super(context,DATABASE_NAME, null, DATABASE_VERSION);
this.context= context;
Message.message(context, "constructor called");
}
#Override
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(CREATE_TABLE);
Message.message(context, "OnCreate called");
}catch (SQLException e)
{
Message.message(context, "" + e);
}
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
try {
db.execSQL(DROP_TABLE);
onCreate(db);
Message.message(context, "Onupgrade called");
}catch (SQLException e)
{
Message.message(context,""+e );
Message.message(context, "Error");
}
}
}
}
And its MainActivity.java
package com.example.sarahn.inserttable;
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
EditText username;
EditText password;
DatabaseAdaptor db;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username =(EditText) findViewById(R.id.etname);
password = (EditText) findViewById(R.id.etpass);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void adduser(View view)
{
String user = username.getText().toString();
String pass = password.getText().toString();
long count =db.insertdata(user,pass);
if(count<0)
{
Message.message(this,"Unsucessful");
}else
{
Message.message(this,"Sucessfull");
}
}
}
Should it adduser method in mainactivity should be look like this?
public void adduser(View view)
{
String user = username.getText().toString();
String pass = password.getText().toString();
db=new DatabaseAdaptor(getApplicationContext());
long count =db.insertdata(user,pass);
if(count<0)
{
Message.message(this,"Unsucessful");
}else
{
Message.message(this,"Sucessfull");
}
please use a valid table name! it seems like you are using table as table name this will cause error!.
You need to leave a white space before table name!
please use the following statement to create your table,
private static final String CREATE_TABLE = "CREATE TABLE "+TABLE_NAME+"("+UID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+NAME+" VARCHAR(255), "+PASSWORD+" VARCHAR(255));";
Note: numeric arguments in parentheses that following the type name (ex: "VARCHAR(255)") are ignored by SQLite - SQLite does not impose any length restrictions
SQLite does not enforce the length of a VARCHAR. You can declare a VARCHAR(10) and SQLite will be happy to let you put 500 characters in it. And it will keep all 500 characters intact - it never truncates.
i have created a database and run a query which add some elements to results.
I want the button that i have, to respond on click and show the results to a new black activity. I will post my current classes.
Sorry for everything but im very new to android programming. :)
package com.example.pota;
import java.util.ArrayList;
import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
public class createDatabase extends ListActivity{
private final String DATABASE_NAME = "potaDB";
private final String DATABASE_TABLE = "olaPota";
private final String DATABASE_TABLE2 = "favorites";
private final int DATABASE_VERSION = 1;
private SQLiteDatabase potaDB=null;;
//Kaleitai otan dimiourgeitai to activiy
public void onCreate(Bundle icicle, Context ctx){
super.onCreate(icicle);
ArrayList <String> results = new ArrayList<String>();
try {
//Dhmiourgei ti vasi an den uparxei alliws tin anoigei
this.openOrCreateDatabase(DATABASE_NAME, DATABASE_VERSION, null);
//Dhmiourgei ena table sti vasi me ta ekseis paidia
potaDB.execSQL("CREATE TABLE IF NOT EXISTS" + DATABASE_TABLE + "(id INT PRIMARY KEY AUTOINCREMENT, name VARCHAR, category VARCHAR, info TEXT, difficulty INT);", null);
//Vazei eggrafes ston pinaka
potaDB.execSQL("INSERT INTO" + DATABASE_TABLE + "(name, category, info, difficulty)" + "VALUES ('Screwdriver', 'Pota', 'i klassiki vodka lemoni', 5);");
//Ena query pou tha mas gurisei ta stoixeia tou pinaka
Cursor c = potaDB.rawQuery("SELECT *" + "FROM" + DATABASE_TABLE,null);
//Pernoume ta dedomena tou pinaka pou xreiazomaste
int name1=c.getColumnIndex("name");
int category1=c.getColumnIndex("category");
int info1=c.getColumnIndex("info");
int difficulty1=c.getColumnIndex("difficulty");
//Pernei ta dedomena ekei pou deixnei o Cursor
String name = c.getString(name1);
String category = c.getString(category1);
String info = c.getString(info1);
int difficulty = c.getInt(difficulty1);
//Prosthetei ta trexontai dedomena sto results
results.add("Onoma Potou: " + name + "Katigoria Potou: " + category + "Suntagi: "+ info + "Duskolia: " + difficulty);
} catch(Exception e) {
System.out.println(e);
}finally {
if (potaDB != null)
potaDB.close();
}
}
}
And the Main Activity:
package com.example.pota;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Ok, I'm not sure which Activity you want to use the button in but do something like:
public class MainActivity extends Activity {
Button myBtn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myBtn = (Button) findViewById(R.id.my_button);
mBtn.setOnclickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this, ReceivingActivity.class);
intent.putExtra("key", value); //name key whatever you want then value is whatever you are sending
startActivity(intent); //this starts the next activity through an intent
}
}
There are different ways to use onClick() but this is probably the most popular but it just depends on what you need. Here is one of my answers that shows how to do it using xml
You also need to Read about Intents and understand how to use them and what they are capable of.
To get the data in your other Activity you will do something like
public void onCreate()
{
...
Intent recIntent = getIntent();
String variableName = recIntent.getStringExtra("key");
}
Hi I am working with my application project.. It just happen that after I click on the login button, an error message pops out saying that Sorry! The application has stopped unexpectedly. Please try again. What is the error of this? please help thanks
This was my code for the data base of the user..
package com.gomez.android;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class dbuser{
public static final String user_name = "username";
public static final String user_password = "password";
public static final String row_id = "_id";
private static final String TAG = "UdbAdapter";
private DatabaseHelper UdbHelper;
private SQLiteDatabase Udb;
/**
* Database creation sql statement
*/
private static final String DATABASE_CREATE =
"create table pages (_id integer primary key autoincrement, "
+ "username text not null, password text not null);";
private static final String DATABASE_NAME = "UserAccount";
private static final String DATABASE_TABLE = "User";
private static final int DATABASE_VERSION = 1;
private Context context = null;
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS pages");
onCreate(db);
}
}
public dbuser(Context cntxt) {
this.context = cntxt;
UdbHelper = new DatabaseHelper(context);
}
public void open() throws SQLException {
Udb = UdbHelper.getWritableDatabase();
}
public void close() {
UdbHelper.close();
}
public long createaccount(String username, String password)
{
Udb = UdbHelper.getWritableDatabase();
ContentValues initialValues = new ContentValues();
initialValues.put(user_name, username);
initialValues.put(user_password, password);
return Udb.insert(DATABASE_TABLE, null, initialValues);
}
public boolean Login(String username, String password)throws SQLException
{
Cursor mCursor = Udb.rawQuery(DATABASE_TABLE, new String[]{username,password});
if (mCursor != null){
if(mCursor.getCount() > 0){
return true;
}
}
return false;
}
}
and this was my login page code.....
package com.gomez.android;
import com.gomez.android.dbuser;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class login extends Activity{
//Declare views
private EditText uname;
private EditText pword;
private Button btnlogin;
private Button btncancel;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set Activity Layout
setContentView(R.layout.login);
//Get EditText and Button References
uname = (EditText)findViewById(R.id.username);
pword = (EditText)findViewById(R.id.password);
btnlogin = (Button)findViewById(R.id.login_enter);
btncancel = (Button)findViewById(R.id.cancel);
//set Click Listener
btnlogin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Check Login
final String username = uname.getText().toString();
final String password = pword.getText().toString();
dbuser users = new dbuser(login.this);
users.open();
if(users.Login(username, password)){
if(username.equalsIgnoreCase(username)&& password.equalsIgnoreCase(password))
{
Toast.makeText(login.this,"Successfully Logged In", Toast.LENGTH_LONG).show();
Intent i = new Intent(login.this, firstpage.class);
startActivity(i);
}
else{
Toast.makeText(login.this,"Invalid Username/Password", Toast.LENGTH_LONG).show();
}
users.close();
}
}
});
btncancel.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
//close application
finish();
}
});
}
}
I can't be sure what the problem is with your code since you didn't provide any information from the LogCat, but it is possible that getWriteableDatabase() is returning a cached database when running the application (I often ran into this problem when implementing and testing a database for the first time).
To ensure this is not the problem, go to Settings -> Applications -> Manage Applications -> [Your Application] -> Clear Data, before running the application from Eclipse. This is an easy way to ensure you are working with your most up-to-date implementation during the early stages of implementing/testing the database.
This very well might not be the problem, but it is one of those things that you wouldn't expect to be the issue (which often leads to hours of frustration), so I thought I'd bring it up :).