Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLiteException: no such table exists
    primarykey
    data
    text
    <p>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!</p> <p>Adapter:</p> <pre><code>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); } </code></pre> <p>Calling code: package bhekman.test.database;</p> <pre><code>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(); } } </code></pre> <p>LogCat Error:</p> <pre><code>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.&lt;init&gt;(SQLiteCompiledSql.java:65) 01-05 22:06:29.030: E/AndroidRuntime(4785): at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:83) 01-05 22:06:29.030: E/AndroidRuntime(4785): at android.database.sqlite.SQLiteStatement.&lt;init&gt;(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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload