Android and SQlite - missing a column?


Gabriu

Here is my DataBase.java. However, when queried in MainActivity, LogCat shows "No such column: Event_id"

static final String tableName="EventList";
static final String colID="Event_id";
static final String colTitle="Title";
static final String colDetails="Details";
static final String colYear="YY";
static final String colMonth="MM";
static final String colDay="DD";
static final String colHour="HH";
static final String colMinute="TT";

public DateBase(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
    super(context, name, factory, version);
}

@Override
public void onCreate(SQLiteDatabase db) {
    String createDB= "create table "+tableName+"("+colID+"integer primary key , "+colTitle+" text not null, "+colDetails+" text, "+colYear+" int, "+colMonth+" int, "+colDay+" int, "+colHour+" int, "+colMinute+" int)";
    db.execSQL(createDB);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    String dropTableSQL = "DROP TABLE IF EXISTS "  + tableName + " ";
    db.execSQL(dropTableSQL);
    onCreate(db);
}

public void execSQL(String sql, Object[] args) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.execSQL(sql, args);
}

public Cursor query(String sql, String[] args) {

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(sql, args);
    return cursor;
}

}

LogCat reports:

11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gabelyu.myapplication/com.example.gabelyu.myapplication.MainActivity}: android.database.sqlite.SQLiteException: no such column: Event_id (code 1): , while compiling: SELECT Event_id as _id, Title, Details, YY, MM, DD, HH, TT FROM EventList
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2249)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.app.ActivityThread.access$700(ActivityThread.java:154)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:99)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:137)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5306)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:  Caused by: android.database.sqlite.SQLiteException: no such column: Event_id (code 1): , while compiling: SELECT Event_id as _id, Title, Details, YY, MM, DD, HH, TT FROM EventList
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1090)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:663)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1420)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1267)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1138)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1306)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at com.example.gabelyu.myapplication.MainActivity.onCreate(MainActivity.java:40)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:5255)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at com.qihoo360.mobilesafe.loader.c.callActivityOnCreate(SourceFile:98)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2213)
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299) 
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.app.ActivityThread.access$700(ActivityThread.java:154) 
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284) 
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:99) 
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:137) 
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5306) 
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511) 
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 
11-12 13:25:22.895 6410-6410/com.example.gabelyu.myapplication E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)

Does this mean that the primary key cannot be selected? Or does android just supervise the column? thanks.

Julian

You forgot to put the correct spaces somewhere, that's why it created the wrong table. Here is the correct string code:

String createDB = "create table "+tableName+" ("+colID+" integer primary key , "+colTitle+" text not null, "+colDetails+" text, "+colYear+" int, "+colMonth+" int, "+colDay+" int, "+colHour+" int, "+colMinute+" int)";

Edit: I formatted your sql query string, let me know if it works. Can you also edit the post and include the sql command to get the item from the database?

String createDB = "CREATE TABLE " + tableName + "(" + colID + " INTEGER PRIMARY KEY," + colTitle + " TEXT not null," + colDetails + " TEXT," + colYear + " INTEGER," + colMonth + " INTEGER," + colDay + " INTEGER," + colHour + " INTEGER," + colMinute + " INTEGER)";

Related


SQLite exception: No such column in Android

username I wrote an application to update rows in SQlite Db, here is the updated code in the data handler: public long updatedata(String ID, String NAME,String NUMBER) { ContentValues content = new ContentValues(); content.put(name, NAME);

SQLite no such column error on Android

Topico I have a problem inserting data from CSV. The CSV part works, but the insert returns the following error. Basically, it says the column doesn't exist. Here is the code as well as the code for the database. 09-06 17:52:22.725: E/AndroidRuntime(19168): FA

SQLite Android no such column error

Andy I'm trying to use SQLite in android, but for some reason I'm having no such column error. I think the error might be syntax, but I can't seem to find it. Here is my code: @Override public void onCreate(SQLiteDatabase database) { d

SQLite no such column error on Android

Topico I have a problem inserting data from CSV. The CSV part works, but the insert returns the following error. Basically, it says the column doesn't exist. Here is the code as well as the code for the database. 09-06 17:52:22.725: E/AndroidRuntime(19168): FA

Android SQLite exception: No such column

catch up I added a date field to the database, but I got an error saying "No such column named date". Can anyone point out where my mistake is? private static final String UID = "id"; private static final String NAME = "Bmi"; private static

No such column SQLite Android

Noah Does anyone know why I'm getting the "no" error for a column named COL2? Error inserting COL2=sdfsdf android.database.sqlite.SQLiteException: table TWhereToGoList has no column named COL2 (code 1 SQLITE_ERROR): , while compiling: INSERT INTO TWhereToG

No column error: SQLite Android

Charini Nanayakkara Even though there are no bugs in this app, it crashes every time Vactivity is called. LogCat shows that table Analysis_for_Today has no column named Activated. Please assist me in finding out what I am doing wrong. MainActivity class (start

SQLite exception: No such column in Android

username I wrote an application to update rows in SQlite Db, here is the updated code in the data handler: public long updatedata(String ID, String NAME,String NUMBER) { ContentValues content = new ContentValues(); content.put(name, NAME);

SQLite Android no such column error

Andy I'm trying to use SQLite in android, but for some reason I'm having no such column error. I think the error might be syntax, but I can't seem to find it. Here is my code: @Override public void onCreate(SQLiteDatabase database) { d

Android SQLite exception: No such column

catch up I added a date field to the database, but I got an error saying "No such column named date". Can anyone point out where my mistake is? private static final String UID = "id"; private static final String NAME = "Bmi"; private static

No such column SQLite Android

Noah Does anyone know why I'm getting the "no" error for a column named COL2? Error inserting COL2=sdfsdf android.database.sqlite.SQLiteException: table TWhereToGoList has no column named COL2 (code 1 SQLITE_ERROR): , while compiling: INSERT INTO TWhereToG

SQLite Android no such column error

Andy I'm trying to use SQLite in android, but for some reason I'm having no such column error. I think the error might be syntax, but I can't seem to find it. Here is my code: @Override public void onCreate(SQLiteDatabase database) { d

No column error: SQLite Android

Charini Nanayakkara Even though there are no bugs in this app, it crashes every time Vactivity is called. LogCat shows that table Analysis_for_Today has no column named Activated. Please assist me in finding out what I am doing wrong. MainActivity class (start

android room relationship: missing column

linux_lover I'm having trouble defining a relationship between two entities. Relationships are one-to-one. Each device is assigned to a room. Device entity: @Entity data class Device( @PrimaryKey(autoGenerate = false) val ipAddress: String, val deviceName:

Unable to create column in SQLite Android

Duc Nguyen Minh: I have this problem: /SQLiteLog: (1) Table ds_sinhvien has no column named id E/SQLiteDatabase: Error inserting name=id=1 class=MMTT2011 android.database.sqlite.SQLiteException: Table ds_sinhvien has no column named id (code 1 SQLITE_ERROR): w

Android SQLite update column with array

Machado Consider the following SQLite table The code snippet below for updating the value at the "bit" position works fine. SQLiteDatabase db = myDbHelper.getReadableDatabase(); ContentValues values = new ContentValues(); values.put("value", "1"); db.update(

Android sqlite update error no such column

User 3576118 I'm currently using sqlite for validation and implementation in my android application. The purpose is to make a history of search keywords. So in this case, I want when the user enters the same keyword but at a different time, I want to push that

Calculate column sum in SQLite Android

Parama Suda I need to calculate Sum value of Column. For this I am using the following query. But when I click the button to calculate, the app crashes. Cursor cur = db.rawQuery("SELECT SUM " + (DbHelper.CART_TOTAL) + " FROM " + DbHelper.CART_TABLE, null); if

SQLite insert no such column error on Android

Topico I have a problem inserting data from CSV. The CSV part works, but the insert returns the following error. Basically saying the column doesn't exist. Below is the code and the code for the database. 09-06 17:52:22.725: E/AndroidRuntime(19168): FATAL EXCE

SQLite insert no such column error on Android

Topico I have a problem inserting data from CSV. The CSV part works, but the insert returns the following error. Basically saying the column doesn't exist. Below is the code and the code for the database. 09-06 17:52:22.725: E/AndroidRuntime(19168): FATAL EXCE

Android SQLite increment column value

David Ben I'm trying to create a score database that increments their "score" by one when they win by calling updateScore(). The primary key and player number are the same (sometimes I may need to restructure the database) and the last column is "score". Here

Android sqlite increase column value

nybler42 I am trying to increase the value by 5 consecutively. I've searched here and on Google, but so far haven't found and answered the question. Here are the places where the least error occurs in Eclipse. private static String[] table_scores = {DHObject.T

Android SQLite error: "Column is not unique"

George I've spent a lot of time looking for an answer but can't find it. I'm trying to use a SQLite database on an Android app, but when I try to use add a new object, I get db.insert(object)an error saying that my primary key is not unique. What am I doing wr

Android sqlite increase column value

nybler42 I am trying to increase the value by 5 consecutively. I've searched here and on Google, but so far haven't found and answered the question. Here are the places where the least error occurs in Eclipse. private static String[] table_scores = {DHObject.T

Android SQLite update column with array

Machado Consider the following SQLite table The code snippet below for updating the value at the "bit" position works fine. SQLiteDatabase db = myDbHelper.getReadableDatabase(); ContentValues values = new ContentValues(); values.put("value", "1"); db.update(

Unable to create column in SQLite Android

Duc Nguyen Minh: I have this problem: /SQLiteLog: (1) Table ds_sinhvien has no column named id E/SQLiteDatabase: Error inserting name=id=1 class=MMTT2011 android.database.sqlite.SQLiteException: Table ds_sinhvien has no column named id (code 1 SQLITE_ERROR): w

Calculate column sum in SQLite Android

Parama Suda I need to calculate Sum value of Column. For this I am using the following query. But when I click the button to calculate, the app crashes. Cursor cur = db.rawQuery("SELECT SUM " + (DbHelper.CART_TOTAL) + " FROM " + DbHelper.CART_TABLE, null); if

SQLite insert no such column error on Android

Topico I have a problem inserting data from CSV. The CSV part works, but the insert returns the following error. Basically saying the column doesn't exist. Below is the code and the code for the database. 09-06 17:52:22.725: E/AndroidRuntime(19168): FATAL EXCE

Android sqlite increase column value

nybler42 I am trying to increase the value by 5 consecutively. I've searched here and on Google, but so far haven't found and answered the question. Here are the places where the least error occurs in Eclipse. private static String[] table_scores = {DHObject.T