1 Replies - 3146 Views - Last Post: 30 November 2013 - 12:31 PM Rate Topic: -----

#1 Cloudyeyes  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 65
  • Joined: 15-May 10

SQLite - SQLiteException: no such column

Posted 30 November 2013 - 12:25 PM

14:19:52.869 1713 List.beta1 ERROR AndroidRuntime at dalvik.system.NativeStart.main(Native Method)
14:19:52.869 1713 List.beta1 ERROR AndroidRuntime Caused by: android.database.sqlite.SQLiteException: no such column: itemID (code 1): , while compiling: SELECT * FROM Items where itemID=?
14:19:52.869 1713 List.beta1 ERROR AndroidRuntime at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
Declarations:
    private static final int DATABASE_VERSION = 1;
    private static final String TABLE_NAME = "Items";
    private static final String itemID = "itemID";
    private static final String details = "details";
    private static final String remainderTime = "remainderTime";
    private static final String owner = "owner";
    private static final String status = "status";

Database create statement:
        @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_NAME + "("
                + itemID + "INTEGER PRIMARY KEY AUTOINCREMENT, "
                + details + " TEXT, " 
                + remainderTime + " INTEGER, "
                + owner + " TEXT, " 
                + status + " TEXT "
                + ");";
        db.execSQL(CREATE_CONTACTS_TABLE);
    }
 
    //to update the table
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // drop the old table
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
 
        //Create the table again
        onCreate(db);
    }
 


Error occurs in method "getItem":
    public ItemsClass getItem(int id) {
        SQLiteDatabase db = this.getReadableDatabase();

        Cursor cursor = db.rawQuery("SELECT * FROM Items where " + itemID + "=?", new String[] {String.valueOf(id)});
        if (cursor != null)
            cursor.moveToFirst();

        ItemsClass Item = new ItemsClass(Integer.parseInt(cursor.getString(0)), cursor.getString(1),
                Integer.parseInt(cursor.getString(2)), cursor.getString(3), cursor.getString(4));
        
        return Item;
    }

This post has been edited by Cloudyeyes: 30 November 2013 - 12:28 PM


Is This A Good Question/Topic? 0
  • +

Replies To: SQLite - SQLiteException: no such column

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2890
  • View blog
  • Posts: 9,597
  • Joined: 12-December 12

Re: SQLite - SQLiteException: no such column

Posted 30 November 2013 - 12:31 PM

+ itemID + "INTEGER PRIMARY KEY AUTOINCREMENT, "

You have no space between "itemID" and "INTEGER". You've probably created a field named "itemIDINTEGER".

This post has been edited by andrewsw: 30 November 2013 - 12:33 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1