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. Fwd: Android Customer Slider





This sounds like a SlidingDrawer. Maybe that suits your needs.
http://developer.android.com/reference/android/widget/SlidingDrawer.html

-------------------------------------------------------------------------------------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices

-- 
.

2. Demo vs Paid and that 15 minutes of refund policy

Now that the market refund policy has changed to 15 minutes, it has
become more important to have a demo version for every paid app. What
are the best practices to maintain a demo version for a paid app,
specially when the development is done in Eclipse. I know that using
ant build file lot of crazy stuff can be done. However one would like
to avoid dealing with ant build files for hobby app development.

-- 

3. LocationManager.KEY_PROXIMITY_ENTERING

4. Developers near Orlando?

5. XmlSerializer issue

6. dell streak Rp3.500.000 bnib

7. SOLD WTS: Car Holder Moto Droid 1 - 2nd (original)