0

I am getting errors from this codes below. I am getting values from the contact.getSellingPrice(), but I can't save it coz of the error. Any help would be a great help.!

Query:

public void onCreate(SQLiteDatabase db) {

    String CREATE_ITEMS = "CREATE TABLE " + TABLE_ITEMS + "(" + KEY_ID
            + " TEXT," + KEY_NAME + " TEXT," + KEY_PRICE + " TEXT," + KEY_ITEM_ID + " TEXT" +")";

    try {
        db.execSQL(CREATE_ITEMS);
        //db.execSQL(CREATE_PATH);
    } catch (SQLException e) {
        e.printStackTrace();
    }

}

DatabaseHandler:

private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_IMAGE_PATH = "itemimagepath";
private static final String KEY_PRICE = "sellingprice";
private static final String KEY_ITEM_ID = "itemid";

void addItems(Menu contact, String TABLE_NAME) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();

    values.put(KEY_ID, contact.getID()); // Contact Name
    values.put(KEY_NAME, contact.getName());
    values.put(KEY_PRICE, contact.getSellingPrice());
    values.put(KEY_ITEM_ID, contact.getItemId());

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

}

LogCat:

07-04 17:01:48.033: E/SQLiteLog(9324): (1) table items has no column named itemid
07-04 17:01:48.037: E/SQLiteDatabase(9324): Error inserting id=BUFFET LUNCH1 itemid=14 sellingprice=370.00 name=BUFFET LUNCH
07-04 17:01:48.037: E/SQLiteDatabase(9324): android.database.sqlite.SQLiteException: table items has no column named itemid (code 1): , while compiling: INSERT INTO items(id,itemid,sellingprice,name) VALUES (?,?,?,?)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at com.jinisys.restoplusordering.DatabaseHandler.addItems(DatabaseHandler.java:140)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at com.jinisys.restoplusordering.LoadItemsActivity$LoadAllProducts.doInBackground(LoadItemsActivity.java:299)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at com.jinisys.restoplusordering.LoadItemsActivity$LoadAllProducts.doInBackground(LoadItemsActivity.java:1)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-04 17:01:48.037: E/SQLiteDatabase(9324):     at java.lang.Thread.run(Thread.java:856)
rahstame
  • 2,148
  • 4
  • 23
  • 53
  • Are you sure that you are creating column with name `itemid` in your table? – hardartcore Jul 04 '13 at 09:16
  • "table items has no column named itemid" Are you sure that this is the name of that column??? – nano_nano Jul 04 '13 at 09:17
  • yes, I'll add something. – rahstame Jul 04 '13 at 09:58
  • The column name should be consistent since it appears to use the same definition. Are you calling 'db.execSQL(CREATE_ITEMS);' in the onCreate method of the helper? – Graham Povey Jul 04 '13 at 10:03
  • Yes, I am calling it in the onCreate method. I added another thing. – rahstame Jul 04 '13 at 10:08
  • Are you sure that `onCreate` gets executed? – CL. Jul 04 '13 at 10:17
  • Does this fail for a clean installation of the app? i.e. after an uninstall. Possibly due to change in schema without relevant update code. – Graham Povey Jul 04 '13 at 10:19
  • Also, although not strictly necessary here, there is no _uid column which can cause grief with loaders/cursor adapters later. I alweays have my first column as `_uid + INTEGER PRIMARY KEY AUTOINCREMENT` – Graham Povey Jul 04 '13 at 10:21
  • @Graham Povey: Just this table I'm having errors, other tables are working fine with similar look to CREATE_ITEMS. – rahstame Jul 04 '13 at 10:27
  • @CL: other tables together with this is working. – rahstame Jul 04 '13 at 10:27
  • 1
    Have you added the itemId column after you created the table once? In such case, make sure that you have onUpgrade implemented and db version is incremented. – Wand Maker Jul 04 '13 at 10:34
  • Have you added necessary permissions in manifest file. `` and `` – Anupam Jul 04 '13 at 11:08
  • yes, as what I have said other tables are working not the Items table. ^^ what do you think @Anupam? – rahstame Jul 04 '13 at 11:10
  • @lordzden Do one thing, sometimes it creates prm, change your db name and table name to somehting different and try to execute same code and see. If that helps otherwise will have to make a POC for this. Please try changing it and post back the result. – Anupam Jul 04 '13 at 11:22
  • Just use the same query(to insert data) in your sqlite(command prompt) and see if you are able to insert into the table – Benil Mathew Jul 05 '13 at 13:13
  • @ Wand Maker: I got this resolve effective..thanks!!! guys for all the help and sharing your ideas and knowledge. Good Day! – rahstame Jul 08 '13 at 03:07

1 Answers1

0

If save database on external sdcard than remove it or uninstall app and check.

nilesh patel
  • 834
  • 1
  • 5
  • 10