I keep getting an error:
SQLiteException: no such column: name (code 1): , while compiling: SELECT _id, date, amount, item FROM items_table ORDER BY name
every time I try entering an activity, it crashes and I'm not sure how to go about fixing it. I've tried many options suggested by other users in this forum however to no avail. Any help is greatly appreciated.
This is my Logcat:
It seems to be pointing towards another activity as well called "T_Entertainment"
Here is the 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);
}
and here 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));
}
}
Aucun commentaire:
Enregistrer un commentaire