0

我从下面的代码中收到错误。我从 中获取值contact.getSellingPrice(),但由于错误而无法保存它。任何帮助将是一个很大的帮助。!

询问:

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();
    }

}

数据库处理器:

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

}

日志猫:

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)
4

1 回答 1

0

如果将数据库保存在外部 sdcard 上而不是删除它或卸载应用程序并检查。

于 2013-07-04T13:14:31.473 回答