SQLite Database Force Closing due to Syntax Error - android-sqlite

I am trying to insert into the SQLite Database but it keeps on force closing every time I run my program on the emulator. I think it has something to due with my syntax of my database creation but I have triple checked it and can't find my error. The only other thing I can think of is if I have to add something to the manifest to properly run a SQlite database.
Below is my code for my helper class.
public class dbhelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "swimmers";
public static final String TABLE_SWIMMERS = "sfd table";
public static final String C_ID = "id";
public static final String NAME = "name";
public static final String TEAM = "team";
public static final String NOTES = "notes";
public static final int VERSION = 1;
public dbhelper(Context context)
{
super(context, DATABASE_NAME, null, VERSION);
}
#Override
public void onCreate (SQLiteDatabase db)
{
String createdb = "create table " + TABLE_SWIMMERS + "(" + C_ID + " integer primary key autoincrement, " + NAME + " text, " + TEAM + " text, " + NOTES + " text); ";
db.execSQL(createdb);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
db.execSQL("drop table " + TABLE_SWIMMERS);
onCreate(db);
}
//add new entry
void addSwimmer(Swimmer swimmer){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(NAME, swimmer.getname());
values.put(TEAM, swimmer.getteam());
values.put(NOTES, swimmer.getnotes());
db.insert(TABLE_SWIMMERS, null, values);
db.close();
}
//Getting single swimmer
Swimmer getSwimmer(int id){
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_SWIMMERS, new String[] { C_ID, NAME, TEAM, NOTES}, C_ID + "=?", new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor !=null)
cursor.moveToFirst();
Swimmer swimmer = new Swimmer (Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2), null);
return swimmer;
}
public int updateSwimmer(Swimmer swimmer){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(NAME, swimmer.getname());
values.put(TEAM, swimmer.getteam());
values.put(NOTES, swimmer.getnotes());
return db.update(TABLE_SWIMMERS, values, C_ID + " = ?", new String[] { String.valueOf(swimmer.getID()) });
}
//delete single contact
public void deleteSwimmer(Swimmer swimmer){
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_SWIMMERS, C_ID + " = ?", new String[] { String.valueOf(swimmer.getID()) });
db.close();
}
//get contacts count
public int getSwimmersCount(){
String countQuery = "SELECT * FROM " + TABLE_SWIMMERS;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
return cursor.getCount();
}
}
Below is my Swimmer class that I made and I am trying to insert a Swimmer into the database.
public class Swimmer {
//private variables
int _id;
String _name;
String _team;
String _notes;
public Swimmer(int id, String name, String team, String notes){
this._id = id;
this._name = name;
this._team = team;
this._notes = notes;
}
public Swimmer(String name, String team, String notes){
this._name = name;
this._team = team;
this._notes = notes;
}
public int getID(){
return this._id;
}
public void setID(int id){
this._id = id;
}
public String getname(){
return this._name;
}
public void setname(String name){
this._name = name;
}
public String getteam(){
return this._team;
}
public void setteam(String team){
this._team = team;
}
public String getnotes(){
return this._notes;
}
public void setnotes(String notes){
this._notes = notes;
}
}
Here is my code to open and insert into the database.
public class CreateNewSwimmerProfile extends Activity {
private dbhelper db;
private final String TAG = "Create New Profile";
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.activity_sfdmain, menu);
return true;
}
#Override
public void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Log.i("createProfileActivity", "Intent Text");
setContentView(R.layout.createprofile);
Intent createprofileintent = getIntent();
db = new dbhelper(this);
}
public void btn_CLICK_addswimmer (View w)
{
Log.i("Insert: ", "Inserting ..");
String name,team,notes;
EditText nameIn = (EditText) findViewById(R.id.editText_name);
EditText teamIn = (EditText) findViewById(R.id.editText_team);
EditText notesIn = (EditText) findViewById(R.id.editText_notes);
name = nameIn.getText().toString();
team = teamIn.getText().toString();
notes = notesIn.getText().toString();
Swimmer test = new Swimmer(name, team, notes);
db.addSwimmer(test);
}
public void btn_CLICK_cancel (View b)
{
Log.i(TAG, "start create new profile activity");
Intent intent = new Intent(this, SFDMain.class);
startActivity(intent);
}
}
And here are my errors when I try to insert the swimmer.
11-27 08:58:36.150: E/AndroidRuntime(643): FATAL EXCEPTION: main
11-27 08:58:36.150: E/AndroidRuntime(643): java.lang.IllegalStateException: Could not execute method of the activity
11-27 08:58:36.150: E/AndroidRuntime(643): at android.view.View$1.onClick(View.java:3591)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.view.View.performClick(View.java:4084)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.view.View$PerformClick.run(View.java:16966)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.os.Handler.handleCallback(Handler.java:615)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.os.Handler.dispatchMessage(Handler.java:92)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.os.Looper.loop(Looper.java:137)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-27 08:58:36.150: E/AndroidRuntime(643): at java.lang.reflect.Method.invokeNative(Native Method)
11-27 08:58:36.150: E/AndroidRuntime(643): at java.lang.reflect.Method.invoke(Method.java:511)
11-27 08:58:36.150: E/AndroidRuntime(643): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-27 08:58:36.150: E/AndroidRuntime(643): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-27 08:58:36.150: E/AndroidRuntime(643): at dalvik.system.NativeStart.main(Native Method)
11-27 08:58:36.150: E/AndroidRuntime(643): Caused by: java.lang.reflect.InvocationTargetException
11-27 08:58:36.150: E/AndroidRuntime(643): at java.lang.reflect.Method.invokeNative(Native Method)
11-27 08:58:36.150: E/AndroidRuntime(643): at java.lang.reflect.Method.invoke(Method.java:511)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.view.View$1.onClick(View.java:3586)
11-27 08:58:36.150: E/AndroidRuntime(643): ... 11 more
11-27 08:58:36.150: E/AndroidRuntime(643): Caused by: android.database.sqlite.SQLiteException: near "table": syntax error (code 1): , while compiling: create table sfd table(id integer primary key autoincrement, name text, team text, notes text);
11-27 08:58:36.150: E/AndroidRuntime(643): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
11-27 08:58:36.150: E/AndroidRuntime(643): at com.sfd.swimming.feedback.display.system.dbhelper.onCreate(dbhelper.java:35)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
11-27 08:58:36.150: E/AndroidRuntime(643): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
11-27 08:58:36.150: E/AndroidRuntime(643): at com.sfd.swimming.feedback.display.system.dbhelper.addSwimmer(dbhelper.java:48)
11-27 08:58:36.150: E/AndroidRuntime(643): at com.sfd.swimming.feedback.display.system.CreateNewSwimmerProfile.btn_CLICK_addswimmer(CreateNewSwimmerProfile.java:50)
11-27 08:58:36.150: E/AndroidRuntime(643): ... 14 more
11-27 08:58:36.420: D/dalvikvm(643): GC_CONCURRENT freed 207K, 4% free 8241K/8519K, paused 22ms+33ms, total 304ms
11-27 08:58:38.680: I/Process(643): Sending signal. PID: 643 SIG: 9
ANY help is greatly appreciated!!

table is a Keyword for SQLite. Try to change your variable TABLE_SWIMMERS from TABLE_SWIMMERS = "sfd table"; to TABLE_SWIMMERS = "sfd"; and it will work.

Related

How to appoint values from Firestore to Datapoints

I want to graph blood glucose level with time. Im getting this error
FATAL EXCEPTION: main
Process: com.example.diabefreemob, PID: 4202
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.diabefreemob/com.example.diabefreemob.graph}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.firestore.CollectionReference com.google.firebase.firestore.FirebaseFirestore.collection(java.lang.String)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
public class graph extends AppCompatActivity {
GraphView graphView;
FirebaseFirestore firestore;
FirebaseAuth mAuth;
String Email;
DocumentReference documentReference;
CollectionReference collectionReference;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_graph);
// on below line we are initializing our graph view.
graphView = findViewById(R.id.idGraphView);
mAuth = FirebaseAuth.getInstance();
// Email = Objects.requireNonNull(mAuth.getCurrentUser()).getEmail();
// firestore.collection("users").document(firebase.auth().currentUser.uid).collection("BG").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
List<DataPoint> datapoints = new ArrayList();
Query query = firestore.collection("users").document(Email).collection("BG")
.orderBy("timeStamp");
query.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
#Override
public void onSuccess(QuerySnapshot querySnapshot) {
Log.i(TAG, "Successfully fetched data from firestore");
int index = 0;
for (QueryDocumentSnapshot document : querySnapshot) {
Map data = document.getData();
String glucoseAmount = (String) data.get("Blood Glucose");
datapoints.add(new DataPoint(Double.parseDouble(glucoseAmount), index));
index++;
}
}
});
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(datapoints.toArray(new DataPoint[datapoints.size()]));
graphView.setTitle("My Graph View");
graphView.setTitleColor(R.color.purple_200);
graphView.setTitleTextSize(18);
graphView.addSeries(series);
}
}
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.firestore.CollectionReference com.google.firebase.firestore.FirebaseFirestore.collection(java.lang.String)' on a null object reference
at com.example.diabefreemob.graph.onCreate(graph.java:60)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)`
Can someone please explain where im going wrong

Error in SQLite db creation and Inserting data

When trying to create a database with a single table I encountered the following error. Not able to point the issue causing the error. Although have created the table column, still responding with no such column
Logcat data:
03-16 12:08:35.954 1249-1249/com.example.bharathduraiswamy.comboedittext E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.example.bharathduraiswamy.comboedittext/com.example.bharathduraiswamy.comboedittext.AddSupplier}: android.database.sqlite.SQLiteException: no such
column: _id (code 1): , while compiling: SELECT _id, supplier_name, supplier_contact_number, supplier_address FROM SUPPLIER
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2313)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365)
at android.app.ActivityThread.access$600(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5336)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: no such column: _id (code 1): , while compiling: SELECT _id, supplier_name, supplier_contact_number,
supplier_address FROM SUPPLIER
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:886)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:497)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
at com.example.bharathduraiswamy.comboedittext.VivzDatabaseAdapter.getAllRows(VivzDatabaseAdapter.java:78)
at com.example.bharathduraiswamy.comboedittext.AddSupplier.populateListView(AddSupplier.java:271)
at com.example.bharathduraiswamy.comboedittext.AddSupplier.onCreate(AddSupplier.java:71)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2277)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365)
            at android.app.ActivityThread.access$600(ActivityThread.java:156)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:153)
            at android.app.ActivityThread.main(ActivityThread.java:5336)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)
MainActivity.java data:
DBAdapter myDb;
AutoCompleteTextView customerName;
EditText customerNumber, customerAddress;
customerName = (AutoCompleteTextView) findViewById(R.id.addCustomerName);
customerNumber = (EditText) findViewById(R.id.addCustomerNumber);
customerAddress = (EditText) findViewById(R.id.addCustomerAddress);
openDB();
private void openDB() {
myDb = new DBAdapter(this);
myDb.open();
}
public void addCustomer(MenuItem item) {
if (!TextUtils.isEmpty(customerName.getText().toString()) &&
!TextUtils.isEmpty(customerNumber.getText().toString())) {
myDb.insertCustomer(
customerName.getText().toString(),
customerNumber.getText().toString(),
customerAddress.getText().toString());}
}
DbHelper data: (Edited)
package com.example.bharathduraiswamy.comboedittext;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBAdapter {
private static final String TAG = "DBAdapter"; //used for logging database version changes
/////////////////
//START : CUSTOMER DATA
/////////////////
// Field Names:
public static final String CUSTOMER_ROWID = "customer_id";
public static final String CUSTOMER_NAME = "customer_name";
public static final String CUSTOMER_CONTACT_NUMBER = "customer_contact_number";
public static final String CUSTOMER_CONTACT_ADDRESS = "customer_contact_address";
public static final String[] CUSTOMER_KEYS = new String[] {CUSTOMER_ROWID, CUSTOMER_NAME, CUSTOMER_CONTACT_NUMBER, CUSTOMER_CONTACT_ADDRESS};
// Column Numbers for each Field Name:
public static final int COL_CUSTOMER_ROWID = 0;
public static final int COL_CUSTOMER_NAME = 1;
public static final int COL_CUSTOMER_CONTACT_NUMBER = 2;
public static final int COL_CUSTOMER_CONTACT_ADDRESS = 3;
// DataBase info:
public static final String DATABASE_NAME = "dbLeder";
public static final String CUSTOMER_TABLE = "CUSTOMERLIST";
public static final int DATABASE_VERSION = 3; // The version number must be incremented each time a change to DB structure occurs.
//SQL statement to create database
private static final String DATABASE_CREATE_SQL =
"CREATE TABLE " + CUSTOMER_TABLE
+ " ("
+ CUSTOMER_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ CUSTOMER_NAME + " VARCHAR(255), "
+ CUSTOMER_CONTACT_NUMBER + " VARCHAR(255), "
+ CUSTOMER_CONTACT_ADDRESS + " VARCHAR(255));";
public final Context context;
public DatabaseHelper myDBHelper;
public SQLiteDatabase db;
/////////////////
//END : CUSTOMER DATA
/////////////////
public DBAdapter(Context ctx) {
this.context = ctx;
myDBHelper = new DatabaseHelper(context);
}
// Open the database connection.
public DBAdapter open() {
db = myDBHelper.getWritableDatabase();
return this;
}
// Close the database connection.
public void close() {
myDBHelper.close();
}
//onClick Method for Check - addCustomer
public long insertCustomer(String custName, String custContactNumber, String custContactAddress) {
ContentValues initialValues = new ContentValues();
initialValues.put(CUSTOMER_NAME, custName);
initialValues.put(CUSTOMER_CONTACT_NUMBER, custContactNumber);
initialValues.put(CUSTOMER_CONTACT_ADDRESS, custContactAddress);
// Insert the data into the database.
return db.insert(CUSTOMER_TABLE, null, initialValues);
}
// Delete a row from the database, by rowId (primary key)
public boolean deleteRow(long rowId) {
String where = CUSTOMER_ROWID + "=" + rowId;
return db.delete(CUSTOMER_TABLE, where, null) != 0;
}
public void deleteAll() {
Cursor c = getAllRows();
long rowId = c.getColumnIndexOrThrow(CUSTOMER_ROWID);
if (c.moveToFirst()) {
do {
deleteRow(c.getLong((int) rowId));
} while (c.moveToNext());
}
c.close();
}
// Return all data in the database.
public Cursor getAllRows() {
String where = null;
Cursor c = db.query(true, CUSTOMER_TABLE, CUSTOMER_KEYS, where, null, null, null, null, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
// Get a specific row (by rowId)
public Cursor getRow(long rowId) {
String where = CUSTOMER_ROWID + "=" + rowId;
Cursor c = db.query(true, CUSTOMER_TABLE, CUSTOMER_KEYS,
where, null, null, null, null, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
// Change an existing row to be equal to new data.
public boolean updateRow(long rowId, String custName, String custContactNumber, String custContactAddress) {
String where = CUSTOMER_ROWID + "=" + rowId;
ContentValues newValues = new ContentValues();
newValues.put(CUSTOMER_NAME, custName);
newValues.put(CUSTOMER_CONTACT_NUMBER, custContactNumber);
newValues.put(CUSTOMER_CONTACT_ADDRESS, custContactAddress);
// Insert it into the database.
return db.update(CUSTOMER_TABLE, newValues, where, null) != 0;
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase _db) {
_db.execSQL(DATABASE_CREATE_SQL);
}
#Override
public void onUpgrade(SQLiteDatabase _db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading application's database from version " + oldVersion
+ " to " + newVersion + ", which will destroy all old data!");
// Destroy old database:
_db.execSQL("DROP TABLE IF EXISTS" + CUSTOMER_TABLE);
onCreate(_db); // Recreates the onCreate()
}
}
}
Nothing strikes me as wrong in your code.
Did you increment the DATABASE_VERSION field to make sure your onUpgradee() method is called ?
If you did that already, maybe try to uninstall the app from your device. That will erase the existing database. If this work, that would probably mean that your onUpgrade() method does not work.
Good luck.
EDIT : Check your onUpgrade() method. You don't have a space after "EXISTS". You need one otherwise the query won't work.
The new Logcat shows that you are having a different error. I think what it tells you is that you should have at least one column called "_id" in your table.
This is sort of a must have when working in SQLite on Android because some of the convenience methods look for this column name.
If you search StackOverflow, you will find some answers tell you that you can Alias this row and don't have to change the design of your table, but I'd say go ahead and change your design.

"java.lang.NullPointerException" Error when trying to insert data to sqlite (Android)

I face the error :
1566-1566/com.example.rom.romproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.rom.romproject, PID: 1566
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3823)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3818)
            at android.view.View.performClick(View.java:4438)
            at android.view.View$PerformClick.run(View.java:18422)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.rom.romproject.ContactView.contactFavorite(ContactView.java:37)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.view.View$1.onClick(View.java:3818)
            at android.view.View.performClick(View.java:4438)
            at android.view.View$PerformClick.run(View.java:18422)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
This happens when im clicking on a button i created.
The button purpose is to insert Data into my sql table.
The SQL class :
public class sqlDatabaseAdapter
{
sqlHelper helper;
public sqlDatabaseAdapter(Context context)
{
helper = new sqlHelper(context);
}
public long insertData(String name, String phone)
{
SQLiteDatabase db = helper.getWritableDatabase();
ContentValues content = new ContentValues();
content.put(sqlHelper.NAME, name);
content.put(sqlHelper.PHONE, phone);
return db.insert(helper.TABLE_NAME, null, content);
}
static class sqlHelper extends SQLiteOpenHelper
{
static final String DATABASE_NAME = "ContactDB";
static final String TABLE_NAME = "Favorites";
static final int DB_VERSION = 1;
static final String UID = "_id";
static final String NAME = "Name";
static final String PHONE = "Phone";
static final String CREATE_TABLE = "CREATE TABLE "+ TABLE_NAME +" ("+UID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+NAME+" VARCHAR(255), "+PHONE+" VARCHAR(255));";
static final String DROP_TABLE = "DROP TABLE IF EXISTS"+TABLE_NAME;
private Context context;
public sqlHelper(Context context)
{
super(context, DATABASE_NAME, null, DB_VERSION);
this.context = context;
Message.Message(context, "Constructor Called");
}
#Override
public void onCreate(SQLiteDatabase db)
{
try {
db.execSQL(CREATE_TABLE);
Message.Message(context, "onCreate Called");
} catch( SQLException e)
{
Message.Message(context, "" + e);
}
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
try {
db.execSQL(DROP_TABLE);
onCreate(db);
Message.Message(context, "OnUpgrade Called");
} catch(SQLException e)
{
Message.Message(context, "" + e);
}
}
}
}
Now, im not rly sure at the source of the problem , so i will post both of my activites.
Btw : the info im trying to insert to the SQL is a contact name and phone
(that i get from the main activity list view).
Main Activity ( List view of phone contacts ) :
public class MainActivity extends ListActivity {
ListView l;
Cursor cursor;
SimpleCursorAdapter listAdapter;
sqlDatabaseAdapter helper;
#Override
public int getSelectedItemPosition()
{
return super.getSelectedItemPosition();
}
#Override
public long getSelectedItemId()
{
return super.getSelectedItemId();
}
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
startManagingCursor(cursor);
String[] from = {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID};
int[] to = {android.R.id.text1,android.R.id.text2};
listAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_2,cursor,from,to);
setListAdapter(listAdapter);
l = getListView();
l.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
helper = new sqlDatabaseAdapter(this);
helper.helper.getWritableDatabase();
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
TextView _tempName= (TextView)v.findViewById(android.R.id.text1);
String _temp = _tempName.getText().toString();
TextView _tempPhone = (TextView)v.findViewById(android.R.id.text2);
String _temp2 = _tempPhone.getText().toString();
Intent intent = new Intent(this, ContactView.class);
intent.putExtra("contactName", _temp);
intent.putExtra("contactPhone", _temp2);
startActivity(intent);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
The second activity (where the button is ) :
public class ContactView extends ActionBarActivity {
Button _Call;
Button _Favorite;
FavoriteContact contact = new FavoriteContact();
sqlDatabaseAdapter helper;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact_view);
_Call = (Button)findViewById(R.id.bCall);
_Favorite = (Button)findViewById(R.id.bFavorite);
contact.setName(getIntent().getExtras().getString("contactName"));
contact.setPhone(getIntent().getExtras().getString("contactPhone"));
setTitle(contact.getName());
}
public void contactFavorite(View view)
{
long id = 0L;
id = helper.insertData(contact.getName(), contact.getPhone());
/*
if( id < 0)
{
Message.Message(this, "Unsuccessful");
}
else
{
Message.Message(this, "Successfully inserted to favorite contacts ");
}
*/
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_contact_view, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Contact class i created and FavoriteContact class :
(favoritecontact extends Contact)
public class Contact
{
private String Name = null;
private String Phone = null;
public String getPhone() {
return Phone;
}
public void setPhone(String phone) {
Phone = phone;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
}
public class FavoriteContact extends Contact
{
private Boolean isFavorite;
public Boolean getIsFavorite() {
return isFavorite;
}
public void setIsFavorite(Boolean isFavorite) {
this.isFavorite = isFavorite;
}
}
i think i gave everything i need...
sorry for my bad english and its my first time posting here so i dont rly know how it works :D
thanks for every bit of help .
The variable helper is never initialized in ContactView.

play.exceptions.JavaExecutionException: Cannot get the object #Id for an object in WAS8

this is my code in controller and here i save my object
public static void newNdsf(Integer cprNumber,String fstCode,Date startDate,
Double amount, Date endDate, String isActive, String userCreated, String msg){
Beneficiary beneficiary = new Beneficiary();
beneficiary.beneficiaryPK = (new BeneficiaryPK(cprNumber, fstCode, startDate));
beneficiary.dateCreated = (new Date());
beneficiary.userCreated = userCreated;
beneficiary.amount = new BigDecimal(amount);
beneficiary.dateLastUpdate = (new Date());
beneficiary.userLastUpdate = userCreated;
beneficiary.endDate = endDate;
if(isActive.charAt(0) == Constants.IN_ACTIVE || isActive.charAt(0) == Constants.ACTIVE)
beneficiary.isActive = isActive.charAt(0);
else
System.out.println("in valid is Active value entered in service");
beneficiary.save();
int count = new CRSServices().savePersonDetails(cprNumber);
System.out.println("Person Data saved from Service : " + count);
msg = msg.concat("Entered Successfully");
renderText(msg);
}
in Models iam overriding the save method to catch some exception
#Override
public <T extends JPABase> T save()
{
long startTs = System.currentTimeMillis();
if (endDate != null && beneficiaryPK != null && beneficiaryPK.startDate != null && endDate.before(beneficiaryPK.startDate)){
throw new RuntimeException("startdate_after_end_date");
}
Object result = super.save();
logger.debug("Save Took: {} " , System.currentTimeMillis() - startTs);
return (T) result;
}
this code is working on WAS6
but when i use it in WAS8
it gives me this exception
#6d2l11n03
Internal Server Error (500)
Execution exception (In /app/models/Beneficiary.java around line 221)
ValidationException occured : error during validation of
play.exceptions.JavaExecutionException: error during validation of <unknown>
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:290)
at play.server.ServletWrapper$ServletInvocation.execute(ServletWrapper.java:476)
at play.Invoker$Invocation.run(Invoker.java:187)
at play.server.ServletWrapper$ServletInvocation.run(ServletWrapper.java:467)
at play.Invoker.invokeInThread(Invoker.java:61)
at play.server.ServletWrapper.service(ServletWrapper.java:117)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1214)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:774)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:456)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1027)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:895)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1659)
Caused by: javax.validation.ValidationException: error during validation of <unknown>
at org.apache.bval.jsr303.ClassValidator.unrecoverableValidationError(ClassValidator.java:633)
at org.apache.bval.jsr303.ClassValidator.validate(ClassValidator.java:161)
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:113)
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:71)
at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:177)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:72)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:267)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:259)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:178)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:345)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:791)
at play.db.jpa.JPABase._save(JPABase.java:47)
at play.db.jpa.GenericModel.save(GenericModel.java:187)
at models.Beneficiary.save(Beneficiary.java:221)
at controllers.NdsfService.newNdsf(NdsfService.java:189)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:413)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:408)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:182)
... 27 more
Caused by: play.exceptions.UnexpectedException: Unexpected Error
at play.db.jpa.JPAPlugin$JPAModelLoader.keyValue(JPAPlugin.java:491)
at play.db.jpa.JPABase._key(JPABase.java:96)
at play.db.jpa.JPABase.hashCode(JPABase.java:226)
at org.apache.bval.jsr303.GraphBeanIdentity.hashCode(GraphBeanIdentity.java:123)
at java.util.HashMap.getEntry(HashMap.java:510)
at java.util.HashMap.get(HashMap.java:498)
at org.apache.bval.jsr303.GroupValidationContextImpl.collectValidated(GroupValidationContextImpl.java:133)
at org.apache.bval.jsr303.ClassValidator.validateBeanNet(ClassValidator.java:421)
at org.apache.bval.jsr303.ClassValidator.validate(ClassValidator.java:141)
... 45 more
Caused by: play.exceptions.UnexpectedException: Cannot get the object #Id for an object of type class models.Beneficiary
at play.db.jpa.JPAPlugin$JPAModelLoader.keyField(JPAPlugin.java:511)
at play.db.jpa.JPAPlugin$JPAModelLoader.keyValue(JPAPlugin.java:489)
... 53 more
if anyone can help!!!
Figured this out
in my object
before i have only
#EmbeddedId
public BeneficiaryPK beneficiaryPK;
and this works in WAS 6 but not in WAS 8
so now i added #Id and both annotations are working in WAS 8
#EmbeddedId
#Id
public BeneficiaryPK beneficiaryPK;
hope this is helpfull

RuntimeException Retrieving data from SQLite Database

I've imported a Database into SQLite (testing.sqllite) which was created in SQLliteManager in Firefox Plugin. I placed it in data/data//databases/.
When I try to retrieve data from the DB, I'm getting runtime exception. Here is my code...
DataBaseHelper.java
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
public class DataBaseHelper extends SQLiteOpenHelper{
public static final String KEY_ROWID = "keyno";
public static final String DESTINATION = "Destination";
public static final String CITY = "City";
public static final String COUNTRY = "Country";
public static final String IMG1 = "Img1";
//The Android's default system path of your application database.
private static String DB_PATH = "/data/data/com.world.destinations/databases/";
private static String DB_NAME = "testing";
private static String DATABASE_TABLE = "Master";
private DataBaseHelper ourHelper;
private SQLiteDatabase myDataBase;
private final Context myContext;
/**
* Constructor
* Takes and keeps a reference of the passed context in order to access to the application assets and resources.
* #param context
*/
public DataBaseHelper(Context context) {
super(context, DB_NAME, null, 1);
this.myContext = context;
}
/**
* Creates a empty database on the system and rewrites it with your own database.
* */
public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
if(dbExist){
//do nothing - database already exist
}else{
//By calling this method and empty database will be created into the default system path
//of your application so we are gonna be able to overwrite that database with our database.
this.getReadableDatabase();
try {
copyDataBase();
} catch (IOException e) {
throw new Error("Error copying database");
}
}
}
/**
* Check if the database already exist to avoid re-copying the file each time you open the application.
* #return true if it exists, false if it doesn't
*/
private boolean checkDataBase(){
SQLiteDatabase checkDB = null;
try{
String myPath = DB_PATH + DB_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}catch(SQLiteException e){
//database does't exist yet.
}
if(checkDB != null){
checkDB.close();
}
return checkDB != null ? true : false;
}
public DataBaseHelper open() throws SQLiteException {
ourHelper = new DataBaseHelper(myContext);
myDataBase = ourHelper.getWritableDatabase();
return this;
}
/**
* Copies your database from your local assets-folder to the just created empty database in the
* system folder, from where it can be accessed and handled.
* This is done by transfering bytestream.
* */
private void copyDataBase() throws IOException{
//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
public void openDataBase() throws SQLException{
//Open the database
String myPath = DB_PATH + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}
#Override
public synchronized void close() {
if(myDataBase != null)
myDataBase.close();
super.close();
}
#Override
public void onCreate(SQLiteDatabase db) {
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public String getData() {
// TODO Auto-generated method stub
String[] columns = new String[]{KEY_ROWID, DESTINATION, CITY, COUNTRY, PERIOD, TYPE, CURRENCY, ELEVATION, BRIEF, HIGHLIGHTS, IMG_MAIN};
Cursor c = myDataBase.query(DATABASE_TABLE, columns, null, null, null, null, null);
String result = "";
int iRow = c.getColumnIndex(KEY_ROWID);
int iName = c.getColumnIndex(DESTINATION);
int iCity = c.getColumnIndex(CITY);
int iCountry = c.getColumnIndex(COUNTRY);
int iImgmain = c.getColumnIndex(IMG1);
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
result = result + c.getString(iRow) + " " + c.getString(iName) + " " + c.getString(iCity) + " " + c.getString(iCountry) + " " + c.getString(iImgmain) + "\n";
}
return result;
}
}
and here is my ShowData.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class ShowData extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.showdata);
TextView tv = (TextView)findViewById(R.id.textView1);
DataBaseHelper info = new DataBaseHelper(this);
info.open();
String data = info.getData();
info.close();
tv.setText(data);
}
}
and here is the exception...
11-14 20:19:29.099: E/AndroidRuntime(933): FATAL EXCEPTION: main
11-14 20:19:29.099: E/AndroidRuntime(933): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.world.destinations/com.world.destinations.ShowData}: android.database.sqlite.SQLiteException: no such table: Master (code 1): , while compiling: SELECT keyno, Destination, City, Country, Img_Main FROM Master
11-14 20:19:29.099: E/AndroidRuntime(933): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-14 20:19:29.099: E/AndroidRuntime(933): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-14 20:19:29.099: E/AndroidRuntime(933): at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-14 20:19:29.099: E/AndroidRuntime(933): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-14 20:19:29.099: E/AndroidRuntime(933): at android.os.Handler.dispatchMessage(Handler.java:99)
11-14 20:19:29.099: E/AndroidRuntime(933): at android.os.Looper.loop(Looper.java:137)
11-14 20:19:29.099: E/AndroidRuntime(933): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-14 20:19:29.099: E/AndroidRuntime(933): at java.lang.reflect.Method.invokeNative(Native Method)
11-14 20:19:29.099: E/AndroidRuntime(933): at java.lang.reflect.Method.invoke(Method.java:511)
11-14 20:19:29.099: E/AndroidRuntime(933): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
Can someone please help me where I'm going wrong. Much appreciated. Thanks.
You are trying to query an empty database.
From stack trace:
SQLiteException: no such table: Master (code 1): , while compiling: SELECT keyno, Destination, City, Country, Img_Main FROM Master
My guess is that you have placed the file in the wrong directory on the sd card and SQLite created a empty database somewhere else.