2015-07-13 2 views
-5

Я получаю ошибку:SQLiteException нет такого столбца (код 1)?

SQLiteException: нет такого столбца: имя (код 1):, в то время компиляции: SELECT _id, дата, количество, элемент из items_table порядка по имени

каждый раз, когда я попробуйте ввести активность, он падает, и я не уверен, как это сделать. Я пробовал много вариантов, предложенных другими пользователями на этом форуме, но безрезультатно. Любая помощь приветствуется.

Это мой Logcat:

Это, кажется, указывая на другой вид деятельности, а также под названием "T_Entertainment"

Вот T_Entertainment.class

prefs = PreferenceManager.getDefaultSharedPreferences(this); 
    initList(); 
    prefs.registerOnSharedPreferenceChangeListener(prefListener); 

    //newEntry = (Button) findViewById(R.id.add_entry); 
    //newEntry.setOnClickListener(new View.OnClickListener() { 

    //@Override 
    //public void onClick(View v) { 
    //startActivity(new Intent(T_Entertainment.this, NewEntry.class)); 
    //} 
} 
//} 

private void initList(){ 
    if (model != null){ 
     stopManagingCursor(model); 
     model.close(); 
    } 
    model = helper.getAll(prefs.getString("sort_order", "name")); 
    startManagingCursor(model); 
    adapter = new ItemAdapter(model); 
    setListAdapter(adapter); 
} 

и здесь is my Helper.class

class Helper extends SQLiteOpenHelper { 
private static final String DATABASE_NAME = "mymanager.db"; 
private static final int SCHEMA_VERSION = 2; 

public Helper(Context context) { 
    super(context, DATABASE_NAME, null, SCHEMA_VERSION); 
} 

@Override 
public void onCreate(SQLiteDatabase db) { 
    // Will be called once when the database is not created 
    db.execSQL("CREATE TABLE items_table (_id INTEGER PRIMARY KEY AUTOINCREMENT, " 
      + "date TEXT, amount TEXT, item TEXT);"); 
} 

@Override 
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
    //Will not be called until 2nd scheme i.e. when SCHEME_VERSION 
    //increases 

} 

/*Read all records from items_table */ 
public Cursor getAll(String orderBy) { 
    return (getReadableDatabase().rawQuery (
      "SELECT _id, date, amount, item FROM items_table ORDER BY " + orderBy, null)); 
} 

/* Read a record from items_table by ID provided */ 
public Cursor getById(String id) { 
    String[] args = { id }; 

    return (getReadableDatabase().rawQuery("SELECT _id, date, amount, item FROM items_table WHERE _ID=?", args)); 
} 

/* Write a record into items_table */ 
public void insert(String date, String amount, String item) { 
    ContentValues cv = new ContentValues(); 

    cv.put("date", date); 
    cv.put("amount", amount); 
    cv.put("item", item); 

    getWritableDatabase().insert("items_table", "name", cv); 
} 

public void update(String id, String date, String amount, String item) { 
    ContentValues cv = new ContentValues(); 
    String[] args = { id }; 
    cv.put("date", date); 
    cv.put("amount", amount); 
    cv.put("item", item); 

    getWritableDatabase().update("items_table", cv, "_ID=?", args); 
} 

public String getID(Cursor c) { 
    return (c.getString(0)); 
} 

public String getDate(Cursor c) { 
    return (c.getString(1)); 
} 

public String getAmount(Cursor c) { 
    return (c.getString(2)); 
} 

public String getItem(Cursor c) { 
    return (c.getString(3)); 
} 

} 
+3

'db.execSQL (" CREATE TABLE items_table (_id INTEGER PRIMARY KEY AUTOINCREMENT, " +" ТЕКСТ ТЕКСТА, сумма ТЕКСТ, ТЕКСТ ТЕЛ.); ");' Где в этой инструкции находится столбец с именем ** name ** ? Я не вижу этого. –

+1

** «Это мой Логкат:» **: Где это? Вы ничего не отправили. – Squonk

ответ

0

Похоже, вы обновляете свою базу данных с предыдущей версии до новой, где вы добавили один столбец. Попробуйте удалить старое приложение с устройства и установить его снова, это не должно быть проблемой.

Смежные вопросы