I read several tutorials and the sqlite section in a book and applied it which works great. Now I messed with it to try and understand it but now it will just force close every single time and i'm not sure why. I've been over my code again and again but maybe I can't find the problem because i'm new to sqlite/databases in general. Any help would be appreciated:
public class Events extends Activity {
private TextView tv;
private DataHelper dh;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tv = new TextView(this);
dh = new DataHelper(this);
dh.deleteAll();
//dh.addEvent("James");
//Cursor c = dh.getEvent();
//startManagingCursor(c);
//tv.setText(dh.showEvent(c));
setContentView(tv);
}
}
public class EventsData extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "events.db";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_CREATE = "CREATE TABLE" + TABLE_NAME + "(" + TITLE + " TEXT)";
private static final String DATABASE_UPGRADE = "DROP TABLE IF EXISTS " + TABLE_NAME;
public EventsData(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL(DATABASE_UPGRADE);
onCreate(db);
}
}
public class DataHelper {
private Context context;
private SQLiteDatabase db;
private EventsData eventsData;
public DataHelper(Context context) {
this.context = context;
eventsData = new EventsData(this.context);
}
public void addEvent(String name) {
db = eventsData.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(TITLE, name);
db.insertOrThrow(TABLE_NAME, null, cv);
}
}
Commenting out addEvent() will run the app fine but once I uncomment it, it force closes.