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


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
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
onCreate()", Toast.LENGTH_SHORT).show();
// Create the table
db.execSQL("DROP TABLE IF EXISTS tbl_users");


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
// 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");

public void onOpen(SQLiteDatabase db) {

and the class extending the activity is as follows

//import android.R.array;

Other Threads

1. Change Text color in listview

Can any one tell me as how to change the text color of items which are
been displayed in a listview.I was able to assign a background color
for the listview but dint find any attributes to change the text


2. Phone?DIY

Can the phone DIY?

3. Manipulating the keyguard lock screen

4. Developer input on -platform discussion

5. nsftools

6. Best way to present a "Loading.." screen

7. hi, i'm new here.and i have a question about how to draw on the surfaceview