SQLite Table没有名为error的列

时间:2015-03-01 15:20:36

标签: android

当我尝试使用SQLite时,存在一些问题......

这是代码

package com.example.demo_ex;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import static android.provider.BaseColumns._ID;

public class SpinnerSelectionDbOpenHelper extends SQLiteOpenHelper {


    private final static String DATABASE_NAME = "spinnerselection.db";
    private final static int DATABASE_VERSION = 1;
    public static final String TABLE_NAME = "spinner_selection";
    public static final String POSITION_SELECTION = "position_selection";
    public static final String ADAPTER_ITEM = "adapter_item";
    public static final String SPINNER_SELECT = "spinner_select";

    public SpinnerSelectionDbOpenHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        final String initTable = "CREATE TABLE " + TABLE_NAME + " (" +
                _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                POSITION_SELECTION + " INTEGER NOT NULL, " +
                ADAPTER_ITEM + " INTEGER NOT NULL, " +
                SPINNER_SELECT + " INTEGER NOT NULL); ";
        db.execSQL(initTable);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

我试图在表格中插入一些值。但错误仍然相同。请帮助!!

03-01 23:02:13.746  12696-12696/com.example.demo_ex E/SQLiteLog﹕ (1) table spinner_selection has no column named spinner_select
03-01 23:02:13.756  12696-12696/com.example.demo_ex E/SQLiteDatabase﹕ Error inserting spinner_select=0 adapter_item=0 position_selection=11
    android.database.sqlite.SQLiteException: table spinner_selection has no column named spinner_select (code 1): , while compiling: INSERT INTO spinner_selection(spinner_select,adapter_item,position_selection) VALUES (?,?,?)

这是我的插入方式。 db是SQLiteDatabase,position_use和positionSpinner_use是私有数据成员。

holder.spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                    @Override
                    public void onItemSelected(AdapterView<?> parent, View view, int position_spinner, long id) {
                        db = dbOpenHelper.getWritableDatabase();

                        position_use = position;
                        positionSpinner_use = position_spinner;

                        ContentValues contentValues = new ContentValues();
                        contentValues.put(POSITION_SELECTION, position_select);
                        contentValues.put(ADAPTER_ITEM, getItemId(position_use));
                        contentValues.put(SPINNER_SELECT, positionSpinner_use);

                        db.insert(TABLE_NAME, null, contentValues);
                    }

0 个答案:

没有答案