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

  • Home
  • SEARCH
  • 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 7925051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:06:10+00:00 2026-06-03T18:06:10+00:00

I am trying to create a SQLite database within my android app, but my

  • 0

I am trying to create a SQLite database within my android app, but my code consistently throws a “SQLiteException” saying that no such table exists. I am new to SQL, but I assume this means my create script isn’t running properly. Part of my code is below. Please point out any errors you see and thanks in advance!

Adapter:

public class DBAdapter
{
public static final String KEY_ID = "_id";
public static final String KEY_NAME = "name";
public static final String KEY_FAVORITE = "favorite";
public static final String KEY_LAT = "lat";
public static final String KEY_LONG = "long";
public static final String KEY_ADDRESS = "address";
public static final String KEY_PHONE = "phone";

private static final String TAG = "DBAdapter";
private static final String DATABASE_NAME = "eateries";
private static final String DATABASE_TABLE = "names";
private static final int DATABASE_VERSION = 1;

private static final String DATABASE_CREATE =
        "create table " + DATABASE_TABLE + "( "
        + KEY_ID + " integer primary key autoincrement, "
        + KEY_NAME + " text not null, "
        + KEY_FAVORITE + " integer, "
        + KEY_LAT + " text not null, "
        + KEY_LONG + " text not null, "
        + KEY_ADDRESS + " text not null, "
        + KEY_PHONE + " 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)
    {
        db.execSQL(DATABASE_CREATE);
    }
    @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 names");
        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 title into the database---
public long insertNew(String name, Integer favorite, GeoPoint coords, String address, String phone)
{
    ContentValues initialValues = new ContentValues();

    initialValues.put(KEY_NAME, name);
    initialValues.put(KEY_FAVORITE, favorite);
    initialValues.put(KEY_LAT, coords.getLatitudeE6());
    initialValues.put(KEY_LONG, coords.getLongitudeE6());
    initialValues.put(KEY_ADDRESS, address);
    initialValues.put(KEY_PHONE, phone);

    return db.insertOrThrow(DATABASE_TABLE, null, initialValues);
}

Calling code:
package bhekman.test.database;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;

public class DatabaseActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        DBAdapter dba = new DBAdapter(this);
        dba.open();
        dba.insertNew("mc. awesome", 1, new GeoPoint(0, 0), "42 SUPER AWESOME DRIVE", "(616)-994-2421");

        Toast.makeText(this, dba.getName(0).getString(0), Toast.LENGTH_LONG).show();
        dba.close();
    }
}

LogCat Error:

01-05 22:06:29.030: E/AndroidRuntime(4785): FATAL EXCEPTION: main
01-05 22:06:29.030: E/AndroidRuntime(4785): java.lang.RuntimeException: Unable to start activity ComponentInfo{bhekman.test.database/bhekman.test.database.DatabaseActivity}: android.database.sqlite.SQLiteException: no such table: names: , while compiling: INSERT INTO names(phone, long, favorite, address, lat, name) VALUES(?, ?, ?, ?, ?, ?);
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.os.Looper.loop(Looper.java:130)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.app.ActivityThread.main(ActivityThread.java:3683)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at java.lang.reflect.Method.invokeNative(Native Method)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at java.lang.reflect.Method.invoke(Method.java:507)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at dalvik.system.NativeStart.main(Native Method)
01-05 22:06:29.030: E/AndroidRuntime(4785): Caused by: android.database.sqlite.SQLiteException: no such table: names: , while compiling: INSERT INTO names(phone, long, favorite, address, lat, name) VALUES(?, ?, ?, ?, ?, ?);
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1149)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1569)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.database.sqlite.SQLiteDatabase.insertOrThrow(SQLiteDatabase.java:1452)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at bhekman.test.database.DBAdapter.insertNew(DBAdapter.java:93)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at bhekman.test.database.DatabaseActivity.onCreate(DatabaseActivity.java:18)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-05 22:06:29.030: E/AndroidRuntime(4785):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-05 22:06:29.030: E/AndroidRuntime(4785):     ... 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-03T18:06:14+00:00Added an answer on June 3, 2026 at 6:06 pm

    It works fine in my computer with your code.
    so I guess that you change the TABLE name during your development. and just run the program again with eclipse’s RUN command. So the application was not a fresh install. but you don’t implement the onUpgrade() correctly.

    to solve your problem you met quickly.

    1. uninstall the program with adb uninstall
    2. reinstall the program.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create image from SQLite database in Java Swing application. But it
I am trying to create a simple app with a SQLite database. I chose
I am trying to create a database for an android app including, in part,
I'm trying to use sqlite as database for a symbian app but I can't
I am trying to insert rows into a SQLite database within Android. A call
I've been trying to get foreign keys working within my Android SQLite database. I
I am trying to create two tables within the same sqlite database. Now, this
I have this error: 12-07 15:27:11.567: E/AndroidRuntime(15797): Caused by: android.database.sqlite.SQLiteException: no such column: recipient:
I am trying to create a SQLite database file for iOS and Android. However,
I'm trying to create a client side app in javascript that downloads a sqlite

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.