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

Assignment Help:
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);
}

@Override
public void onCreate(SQLiteDatabase db)
{
try {
db.execSQL(DATABASE_CREATE);
} catch (SQLException e) {
e.printStackTrace();
}
}

@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 contacts");
onCreate(db);
}
}

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

//---closes the database---
public void close()
{
DBHelper.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) {
mCursor.moveToFirst();
}
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


Related Discussions:- android database file not loading on real device

What is atm cell, Header contains routing and error control information Pay...

Header contains routing and error control information Payload carries the actual user information, either voice, data or video

Graphical bulleted slides, Here are the more specific requirements and the ...

Here are the more specific requirements and the related points - use the below as a check-off list when you make your presentation.  Please note . . . many of the requirements are

Memory unit of computer, Memory unit of computer: The Memory  unit is ...

Memory unit of computer: The Memory  unit is an important component of a computer where all the data and information are stored in the form  of binary digits (combination of 0

Boolean expression, Problem 1. Obtain the truth table and a Boolean exp...

Problem 1. Obtain the truth table and a Boolean expression for the following conditions: x is 0 if any two of the three variables are 1. x is 1 for all other conditions.

Transfer instructions, They are utilized to move the contents of the operat...

They are utilized to move the contents of the operators. Each instruction can be used with many different modes of addressing. MOV MOVS (MOVSB) (MOVSW) MOV INSTRUCTION Principle: D

Magnetic core memory, MAGNETIC CORE MEMORY: This type of memory is used...

MAGNETIC CORE MEMORY: This type of memory is used extensively in airborne digital systems, although integrated circuits are being developed with most modern aircraft systems.

About the faculty posts, is there any oppurtunity for a mca to teach mcasub...

is there any oppurtunity for a mca to teach mcasubjects online

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd