0

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.

0

2 Answers 2

1

Fast shot: There's no space after CREATE TABLE.

Sign up to request clarification or add additional context in comments.

1 Comment

Never knew I needed to add a space. Thanks for the tip.
0

You can check the logcat for the error message. It will tell you what is causing the force close. Link to debugging using logcat Debugging in Android using Eclipse

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.