Use of SQLiteOpenHelper class for using SQLite

by Neo » Tue, 02 Mar 2010 22:22:48 GMT


Sponsored Links
 ello ppl,

I am trying to create an application similar to login form where user
can register themselves for username, password, email etc.The
functionality is as follows.
When the user comes to this app it will be ask to either register or
login. In case of user registering himself he enters firstname,
lastname, username, password and email id using EditText.
On hitting the submit button it should be forwarded to another screen
where he sees his details like username, email etc
I am using SQLite for persisting the data and taking help of
SQLiteOpenHelper for the same. It seems that I am able to create
database and table but no able to insert any values in it. The stack
traces shows that I have an unhandled NullPointer exception

The help class called DatabaseHelper is defined as follows

package com.app.login;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.widget.Toast;

public class DatabaseHelper extends SQLiteOpenHelper
{

public static final int DB_version = 1;
public static final String DB_name = "User";
public SQLiteDatabase database;
public static final String TABLE_NAME = "tbl_users";
//public static final String TABLE_NAME = "tbl_temp";
public static final String CREATE_USER_TABLE = "CREATE TABLE
"+TABLE_NAME+"(id INTEGER PRIMARY KEY AUTOINCREMENT, firstname TEXT,
lastname TEXT, username TEXT, password TEXT, email TEXT);";
LogIn login = new LogIn();
public DatabaseHelper(Context context, String name, CursorFactory
factory,int version)
{
super(context, DB_name, factory,DB_version);
// TODO Auto-generated constructor stub
}

public void onCreate(SQLiteDatabase db)
{

Toast.makeText(login.getApplicationContext(),"In Helper
executing
onCreate()", Toast.LENGTH_SHORT).show();
// Create the table
db.execSQL("DROP TABLE IF EXISTS tbl_users");
db.execSQL(CREATE_USER_TABLE);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
// Housekeeping here.
// Implement how "move" your application data during an
upgrade of
schema versions
// There is no ALTER TABLE command in SQLite, so this
generally
involves
// CREATING a new table, moving data if possible, or
deleting the
old data and starting fresh
// Your call.
//db.execSQL("DROP TABLE IF EXISTS tbl_users");
//onCreate(database);
}

@Override
public void onOpen(SQLiteDatabase db) {
super.onOpen(db);
}
}

--------------------------------------------------------------------------------------------------------------------
and the class extending the activity is as follows
package com.app.login;

//import android.R.array;
import android.app.Activity;



Other Threads

1. Short question: Is HTC Dream multi-touch screen natively? Tks

--~--~---------~--~----~------------~-------~--~----~

2. problem in installing adnroid plugin in eclipse

I read the docs for installing android plugin for eclipse. I did it
according to it and i have downloaded and installed the plugin but
after that when i cliced on Windows-prefrences i could not find
Android in left panel. What could be wrong in it ?
--~--~---------~--~----~------------~-------~--~----~

3. Android Developer Phone Update Problems

4. Themes - Is it possible to apply a style to a specific view ID (that multiple views share) from the Theme?

5. How these android namespace used when declare-styleable?

6. Digital TV on android framework ?

7. EditText linkfy?