Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9164383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:40:12+00:00 2026-06-17T14:40:12+00:00

I have a SQLite database with two tables, one for holding Login information, such

  • 0

I have a SQLite database with two tables, one for holding Login information, such as Email adress and password, and the other one to hold GPS coordinates for the user. I create both tables in the OnCreate method in my DBadapter class “DatabaseHandler.class”.
The login table works perfectly but the Coordinates table doesn’t. The program throws “no such table exists” when I try to access and run commands on it.

Logcat

01-22 12:42:06.769: E/AndroidRuntime(854): FATAL EXCEPTION: main
01-22 12:42:06.769: E/AndroidRuntime(854): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidbasic12/com.example.androidbasic12.map}: android.database.sqlite.SQLiteException: no such table: coord (code 1): , while compiling: SELECT * FROM coord WHERE name = name
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.os.Looper.loop(Looper.java:137)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.app.ActivityThread.main(ActivityThread.java:5039)
01-22 12:42:06.769: E/AndroidRuntime(854):  at java.lang.reflect.Method.invokeNative(Native Method)
01-22 12:42:06.769: E/AndroidRuntime(854):  at java.lang.reflect.Method.invoke(Method.java:511)
01-22 12:42:06.769: E/AndroidRuntime(854):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-22 12:42:06.769: E/AndroidRuntime(854):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-22 12:42:06.769: E/AndroidRuntime(854):  at dalvik.system.NativeStart.main(Native Method)
01-22 12:42:06.769: E/AndroidRuntime(854): Caused by: android.database.sqlite.SQLiteException: no such table: coord (code 1): , while compiling: SELECT * FROM coord WHERE name = name
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
01-22 12:42:06.769: E/AndroidRuntime(854):  at com.example.androidbasic12.library.DatabaseHandler.getLatLng(DatabaseHandler.java:155)
01-22 12:42:06.769: E/AndroidRuntime(854):  at com.example.androidbasic12.library.UserFunctions.getCoords(UserFunctions.java:124)
01-22 12:42:06.769: E/AndroidRuntime(854):  at com.example.androidbasic12.map.onCreate(map.java:56)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.app.Activity.performCreate(Activity.java:5104)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-22 12:42:06.769: E/AndroidRuntime(854):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-22 12:42:06.769: E/AndroidRuntime(854):  ... 11 more

DatabaseHandler.class

public class DatabaseHandler extends SQLiteOpenHelper {

// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "android_api";

//Carcoord table name
private static final String TABLE_CARCOORD = "coord";
// carcoord table columns names
private static final String CAR_KEY_ID = "id";
private static final String CAR_KEY_NAME = "name";
private static final String CAR_KEY_LAT = "lat";
private static final String CAR_KEY_LNG = "lng";


// Login table name
private static final String TABLE_LOGIN = "login";
// Login Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_EMAIL = "email";
private static final String KEY_UID = "uid";
private static final String KEY_CREATED_AT = "created_at";

//Strings that handles create table querys
private static final String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_LOGIN + "("
        + KEY_ID + " INTEGER PRIMARY KEY," 
        + KEY_NAME + " TEXT,"
        + KEY_EMAIL + " TEXT UNIQUE,"
        + KEY_UID + " TEXT,"
        + KEY_CREATED_AT + " TEXT" + ")";
private static final String CREATE_CARCOORD_TABLE = "CREATE TABLE " + TABLE_CARCOORD + "("
        + CAR_KEY_ID + " INTEGER PRIMARY KEY,"
        + CAR_KEY_NAME + " TEXT,"
        + CAR_KEY_LAT + " TEXT,"
        + CAR_KEY_LNG + " TEXT" + ")";

//Constructor
public DatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(CREATE_LOGIN_TABLE);
    db.execSQL(CREATE_CARCOORD_TABLE);

}

// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_LOGIN);
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_CARCOORD);

    // Create tables again
    onCreate(db);
}

/**
 * Store coordinates in TABLEE_COORDS
 */
public void addCoord(String name, String lat, String lng){
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_NAME, name); // Name
    values.put(CAR_KEY_LAT, lat); // latitude
    values.put(CAR_KEY_LNG, lng); //Longitude

    // Inserting row
    db.insert(TABLE_CARCOORD, null, values);
    db.close(); // Closing writable database connection
}

/**
 * Storing user details in database
 * */
public void addUser(String name, String email, String uid, String created_at) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, name); // Name
    values.put(KEY_EMAIL, email); // Email
    values.put(KEY_UID, uid); // Email
    values.put(KEY_CREATED_AT, created_at); // Created At

    // Inserting Row
    db.insert(TABLE_LOGIN, null, values);
    db.close(); // Closing database connection
}

/**
 * Getting user data from database
 * */
public HashMap<String, String> getUserDetails(){
    HashMap<String,String> user = new HashMap<String,String>();
    String selectQuery = "SELECT  * FROM " + TABLE_LOGIN;

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);
    // Move to first row
    cursor.moveToFirst();
    if(cursor.getCount() > 0){
        user.put("name", cursor.getString(1));
        user.put("email", cursor.getString(2));
        user.put("uid", cursor.getString(3));
        user.put("created_at", cursor.getString(4));
    }
    cursor.close();
    db.close();
    // return user
    return user;
}


/**
 * Getting user login status
 * return true if rows are there in table
 * */
public int getRowCount() {
    String countQuery = "SELECT  * FROM " + TABLE_LOGIN;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(countQuery, null);
    int rowCount = cursor.getCount();
    db.close();
    cursor.close();
    // return row count
    return rowCount;
    }
public Cursor getUsername(){
    SQLiteDatabase db = this.getReadableDatabase();
    String query = ("SELECT * FROM " + TABLE_LOGIN + " WHERE name = " + KEY_NAME);
    Cursor cursor = db.rawQuery(query, null);
    return cursor;
}

public Cursor getLatLng(){
    SQLiteDatabase db = this.getReadableDatabase();
    String query = ("SELECT * FROM " + TABLE_CARCOORD + " WHERE name = " + CAR_KEY_NAME);
    Cursor cursor = db.rawQuery(query, null);
    return cursor;

}


/**
 * reset table TABLE_CARCOORD
 */
public void resetCarcoord(){
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(TABLE_CARCOORD, null, null);
    db.close();
}
/**
 * Re create database
 * Delete all tables and create them again
 * */
public void resetTables(){
    SQLiteDatabase db = this.getWritableDatabase();
    // Delete All Rows
    db.delete(TABLE_LOGIN, null, null);
    db.close();
}

}

Code snippet from UserFunctions.class where I use the table “coord”.

    /**
 * Get lat and lng from TABLE_CARCOORDS
 */
public ArrayList<String> getCoords(Context context, String lat, String lng) {
    DatabaseHandler db = new DatabaseHandler(context);
    Cursor cursor = db.getLatLng();
    ArrayList<String> cordarr = new ArrayList<String>();
    if (cursor.moveToFirst()){
        lat = cursor.getString(cursor.getColumnIndex("lat"));
        lng = cursor.getString(cursor.getColumnIndex("lng"));
        cordarr.add(lat);
        cordarr.add(lng);
    }
cursor.close();
db.close();
return cordarr;
}

LogCats after fix

First problem

01-22 14:15:07.080: E/SQLiteDatabase(20980): close() was never explicitly called on database '/data/data/com.example.androidbasic12/databases/android_api' 
01-22 14:15:07.080: E/SQLiteDatabase(20980): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:2072)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1126)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1083)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1170)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:844)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:228)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:157)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:231)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at com.example.androidbasic12.library.DatabaseHandler.getUsername(DatabaseHandler.java:146)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at com.example.androidbasic12.library.UserFunctions.getUname(UserFunctions.java:87)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at com.example.androidbasic12.DashboardActivity.onCreate(DashboardActivity.java:59)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.app.Activity.performCreate(Activity.java:4470)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.os.Looper.loop(Looper.java:137)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at android.app.ActivityThread.main(ActivityThread.java:4511)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at java.lang.reflect.Method.invokeNative(Native Method)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at java.lang.reflect.Method.invoke(Method.java:511)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
01-22 14:15:07.080: E/SQLiteDatabase(20980):    at dalvik.system.NativeStart.main(Native Method)
01-22 14:15:07.080: E/System(20980): Uncaught exception thrown by finalizer
01-22 14:15:07.085: E/System(20980): java.lang.IllegalStateException: Don't have database lock!
01-22 14:15:07.085: E/System(20980):    at android.database.sqlite.SQLiteDatabase.verifyLockOwner(SQLiteDatabase.java:2230)
01-22 14:15:07.085: E/System(20980):    at android.database.sqlite.SQLiteDatabase$1.entryRemoved(SQLiteDatabase.java:2322)
01-22 14:15:07.085: E/System(20980):    at android.database.sqlite.SQLiteDatabase$1.entryRemoved(SQLiteDatabase.java:2318)
01-22 14:15:07.085: E/System(20980):    at android.util.LruCache.trimToSize(LruCache.java:197)
01-22 14:15:07.085: E/System(20980):    at android.util.LruCache.evictAll(LruCache.java:285)
01-22 14:15:07.085: E/System(20980):    at android.database.sqlite.SQLiteDatabase.deallocCachedSqlStatements(SQLiteDatabase.java:2283)
01-22 14:15:07.085: E/System(20980):    at android.database.sqlite.SQLiteDatabase.closeClosable(SQLiteDatabase.java:1255)
01-22 14:15:07.085: E/System(20980):    at android.database.sqlite.SQLiteDatabase.finalize(SQLiteDatabase.java:2043)
01-22 14:15:07.085: E/System(20980):    at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:185)
01-22 14:15:07.085: E/System(20980):    at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:168)
01-22 14:15:07.085: E/System(20980):    at java.lang.Thread.run(Thread.java:856)

Second error

01-22 14:15:07.435: E/AndroidRuntime(20980): FATAL EXCEPTION: main
01-22 14:15:07.435: E/AndroidRuntime(20980): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidbasic12/com.example.androidbasic12.map}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
01-22 14:15:07.435: E/AndroidRuntime(20980):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at android.os.Looper.loop(Looper.java:137)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at android.app.ActivityThread.main(ActivityThread.java:4511)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at java.lang.reflect.Method.invokeNative(Native Method)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at java.lang.reflect.Method.invoke(Method.java:511)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at dalvik.system.NativeStart.main(Native Method)
01-22 14:15:07.435: E/AndroidRuntime(20980): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
01-22 14:15:07.435: E/AndroidRuntime(20980):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at java.util.ArrayList.get(ArrayList.java:304)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at com.example.androidbasic12.map.onCreate(map.java:57)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at android.app.Activity.performCreate(Activity.java:4470)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
01-22 14:15:07.435: E/AndroidRuntime(20980):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
01-22 14:15:07.435: E/AndroidRuntime(20980):    ... 11 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:40:14+00:00Added an answer on June 17, 2026 at 2:40 pm

    have you added below statement db.execSQL(CREATE_CARCOORD_TABLE); in starting only(i mean both table together), or you added it later after creating database.

    I will suggest you to remove/uninstall the application from phone/emulator completely. and install it again and see what it says on execSQL method call. I think if above was the case with you it should probably work.

    The Reason here is onCreate calls once when database is not created hence if it is called once when created db, later on if you add another table, onCreate wont be called hence no added table ll be created. so solution here is either remove app completely and install it again so onCreate ll call now. or increase our database version and do some handling.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have two database files a.sqlite and other one is b.sqlite. suppose table1
I have two tables in a database, one lists package and one lists dependencies:
I have a SQLite database in android with some tables, one of them is
C# (.NET 3.5) I have an SQLite database with two tables - employees (the
I have a simple sqlite database with two tables. When I manually delete (using
I have an SQLite database. I created the tables and filled them with a
I have a database where I store two different kinds of data. One table
I am trying to create two tables within the same sqlite database. Now, this
I have two SQLite databases attached into one connection: db1 and db2. I have
I want built a Android Application with a SQLite Database. I have two Java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.