android database file not loading on real device, Basic Computer Science

i have an android app which uses a database file called question db which is stored in the assets file. I have tried a database example called android application development but for some reason it doesnt seem to work on the real device

Here is the database code

package net.learn2develop.Databases;

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 DBAdapter {
public static final String KEY_ROWID = "_id";
public static final String KEY_NAME = "name";
public static final String KEY_EMAIL = "email";
private static final String TAG = "DBAdapter";

private static final String DATABASE_NAME = "MyDB";
private static final String DATABASE_TABLE = "contacts";
private static final int DATABASE_VERSION = 2;

private static final String DATABASE_CREATE =
"create table contacts (_id integer primary key autoincrement, "
+ "name text not null, email text not null);";

private final Context context;

private DatabaseHelper DBHelper;
private SQLiteDatabase db;

public DBAdapter(Context ctx)
this.context = ctx;
DBHelper = new DatabaseHelper(context);

private static class DatabaseHelper extends SQLiteOpenHelper
DatabaseHelper(Context context)
super(context, DATABASE_NAME, null, DATABASE_VERSION);

public void onCreate(SQLiteDatabase db)
try {
} catch (SQLException e) {

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

//---opens the database---
public DBAdapter open() throws SQLException
db = DBHelper.getWritableDatabase();
return this;

//---closes the database---
public void close()

//---insert a contact into the database---
public long insertContact(String name, String email)
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_NAME, name);
initialValues.put(KEY_EMAIL, email);
return db.insert(DATABASE_TABLE, null, initialValues);

//---deletes a particular contact---
public boolean deleteContact(long rowId)
return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;

//---retrieves all the contacts---
public Cursor getAllContacts()
return db.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_NAME,
KEY_EMAIL}, null, null, null, null, null);

//---retrieves a particular contact---
public Cursor getContact(long rowId) throws SQLException
Cursor mCursor =
db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
KEY_NAME, KEY_EMAIL}, KEY_ROWID + "=" + rowId, null,
null, null, null, null);
if (mCursor != null) {
return mCursor;

//---updates a contact---
public boolean updateContact(long rowId, String name, String email)
ContentValues args = new ContentValues();
args.put(KEY_NAME, name);
args.put(KEY_EMAIL, email);
return db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;

I am wondering if its a problem with my phone

Posted Date: 6/18/2012 5:28:19 PM | Location : United States

Related Discussions:- android database file not loading on real device, Assignment Help, Ask Question on android database file not loading on real device, Get Answer, Expert's Help, android database file not loading on real device Discussions

Write discussion on android database file not loading on real device
Your posts are moderated
Related Questions
Mike sells on the average 15 newspapers per week (Monday – Friday). Find the probability that 2.1 In a given week he will sell all the newspapers

Question 1 . What is an array? Explain Question 2 . What do you mean by optional arguments? Describe Question 3 . Describe in brief about interfaces Question 4

Systems Life Cycle Approach Systems Analysis and Design follows a life cycle for development, as shown below. Brief discussion on this approach is given here: Figure

The CPU has four internal registers, each of 16 bits. The first four, AX, BX, CX, and DX are common use registers and can also be used as 8 bit registers, if used in such a way it

SOCIAL NETWORKING:  A social network is a network of individuals which have some sort of interdependence on each other. This interdependence may be in the form of friendship,

These instructions permit the use of the stack to store or recover data. POP POPF PUSH PUSHF POP INSTRUCTION Purpose: It improves a portion of information from the stack POPF INST

describe the two fundament purpose of surveying

Ms-PowerPoint Presentation for Promoting National Parks You have been hired by Tourism Department to make a presentation to the travel agents from different countries. Design

The GIGO Principle : This is a simple principle with a clear message and universal application - Garbage In - Garbage out! Always try and enter any data in the form you want to

QUESTION a) Cryptography is a set of techniques and mathematical algorithms. Describe four important areas where cryptography must be applied b) What is the importance of us