Android Studio:E / SQLiteLog:(1)表格地方没有名为description_place的列

时间:2016-06-11 17:43:50

标签: android database

我一直收到这个错误“表格​​地方没有名为description_place的clumn”对于android来说仍然是新手,所以不知道为什么会发生这种情况,有人能发现错误吗?

这是我的数据库类:

public class BDManager {
    private static final String TABLE_NAME = "places";
    public static final String KEY_ID_PLACE = "_id";
    public static final String KEY_NOM_PLACE = "nom_place";
    public static final String KEY_TYPE_PLACE = "type_place";
    public static final String KEY_ADDRESS_PLACE = "address_place";
    public static final String KEY_DESCRIPTION_PLACE = "description_place";
    public static final String CREATE_TABLE_PLACES = "CREATE TABLE "
            + TABLE_NAME + "("
            + KEY_ID_PLACE + " INTEGER PRIMARY KEY, "
            + KEY_NOM_PLACE +" TEXT, "
            + KEY_TYPE_PLACE +" TEXT, "
            + KEY_ADDRESS_PLACE +" TEXT, "
            + KEY_DESCRIPTION_PLACE +" TEXT);";

    private MySQLite maBaseSQLite;
    private SQLiteDatabase db;

    public BDManager(Context context){
        maBaseSQLite = MySQLite.getInstance(context);
    }

    public void open() {
        db = maBaseSQLite.getWritableDatabase();
    }

    public void close() {
        db.close();
    }

    public long addPlace(BD place){
        ContentValues values = new ContentValues();
        values.put(KEY_NOM_PLACE, place.getNom_place());
        values.put(KEY_TYPE_PLACE, place.getType_place());
        values.put(KEY_ADDRESS_PLACE, place.getAddress_place());
        values.put(KEY_DESCRIPTION_PLACE, place.getDescription_place());

        return db.insert(TABLE_NAME,null,values);
    }

    public int modPlace(BD place){
        ContentValues values = new ContentValues();
        values.put(KEY_NOM_PLACE, place.getNom_place());
        values.put(KEY_TYPE_PLACE, place.getType_place());
        values.put(KEY_ADDRESS_PLACE, place.getAddress_place());
        values.put(KEY_DESCRIPTION_PLACE, place.getDescription_place());

        String where = KEY_ID_PLACE+" = ?";
        String[] whereArgs = {place.getId_place()+""};

        return db.update(TABLE_NAME, values, where, whereArgs);
    }

    public BD getPlace(int id){
        BD p = new BD("","","","");

        Cursor c = db.rawQuery("SELECT * FROM "+TABLE_NAME+" WHERE    "+KEY_ID_PLACE+"="+id, null);
        if (c.moveToFirst()){
            p.setId_place(c.getInt(c.getColumnIndex(KEY_ID_PLACE)));
           p.setNom_place(c.getString(c.getColumnIndex(KEY_NOM_PLACE)));
           p.setType_place(c.getString(c.getColumnIndex(KEY_TYPE_PLACE)));
       p.setAddress_place(c.getString(c.getColumnIndex(KEY_ADDRESS_PLACE)));
 p.setDescription_place(c.getString(c.getColumnIndex(KEY_DESCRIPTION_PLACE)));

            c.close();
        }
        return p;
    }

    public Cursor getPlaces(){
        return db.rawQuery("SELECT * FROM "+TABLE_NAME, null);
    }
}

当我尝试使用addplace函数保存一个地方时出现错误:

 public void savePlace(View view) {
    final EditText name = (EditText) findViewById(R.id.NomPlace);
    final Spinner type = (Spinner) findViewById(R.id.TypePlace);
    final EditText address = (EditText) findViewById(R.id.AdressePlace);
    final EditText description = (EditText)  findViewById(R.id.DescriptionPlace);

    BDManager sav = new BDManager(this);
    sav.open();
    sav.addPlace(new BD(name.getText().toString() ,type.getSelectedItem().toString() , address.getText().toString(),description.getText().toString()));
    sav.close();

    name.setText("");
    type.setSelection(0);
    address.setText("");
    description.setText("");
}

以下是完整错误:

table places has no column named description_place
Error inserting description_place= nom_place=fyeyryfu address_place=dure type_place=Default
   android.database.sqlite.SQLiteException: table places has no column named description_place (code 1): , while compiling: INSERT INTO places(description_place,nom_place,address_place,type_place) VALUES (?,?,?,?)
   #################################################################
   Error Code : 1 (SQLITE_ERROR)
   Caused By : SQL(query) error or missing database.
    (table places has no column named description_place (code 1): , while compiling: INSERT INTO places(description_place,nom_place,address_place,type_place) VALUES (?,?,?,?))
   #################################################################
       at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
       at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1093)
       at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:670)
       at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
       at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
       at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
       at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1607)
       at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1479)
       at com.myfavoriteplaces.myfavoriteplaces.BDManager.addPlace(BDManager.java:49)
       at com.myfavoriteplaces.myfavoriteplaces.SavePlaces.savePlace(SavePlaces.java:124)
       at java.lang.reflect.Method.invoke(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
       at android.view.View.performClick(View.java:5076)
       at android.view.View$PerformClick.run(View.java:20279)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5910)
       at java.lang.reflect.Method.invoke(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)

有人能帮助我吗?

2 个答案:

答案 0 :(得分:0)

老兄,我会要求一根魔杖,但随后......尤里卡(没有像希腊老兄这样的裸体参与:-))我曾经有过类似的问题

  • 词语和文字之间的单一空间是必需的

    KEY_DESCRIPTION_PLACE +&#34; TEXT);&#34 ;;

    我相信一个UPVOTE是最不可能的提议

    主要是当一个缺失的列错误破坏了android成功的梦想......它是输入错误的原因。

    Heil Android !!!

答案 1 :(得分:0)

更改数据库信息时,需要在OnOpdate()中删除表

如果您想保留自己的onCreate和OnUpdate(MySQLite)代码,请予以修复