Darren Murtagh
Darren Murtagh

Reputation: 591

Android Class crashes, not sure why

i am trying to create a class that will show the contents of a database and i have been using a Tutorial to find out the method of doing this. after doing the tutorial i thought i had a method f showing the contents of the database.

here is the class that will not work:

public class WorkoutProgress extends ListActivity {
private DataBaseHelper datasource;
@Override
public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.progress);

    datasource = new DataBaseHelper(this);
    datasource.open();
    fillData();
    datasource.close();
}
 private void fillData() {
        // Get all of the notes from the database and create the item list
        Cursor c = datasource.getAllTitles();
        startManagingCursor(c);

        String[] from = new String[] { DataBaseHelper.KEY_TITLE };
        int[] to = new int[] { R.id.text1 };

        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter notes =
            new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
        setListAdapter(notes);
    }

}

ok sorry i forgot to clarify a couple of things . one this classs will not open and instead crashes the application. the logcat for this class is here

04-03 14:31:25.556: ERROR/Database(14884): Failure 1 (near "tableacts": syntax error) on 0x2c2a00 when preparing 'create tableacts (id2integer primary key autoincrement, datetext not null,steps text not null, calories text not null);'. 04-03 14:31:25.556: DEBUG/AndroidRuntime(14884): Shutting down VM 04-03 14:31:25.556: WARN/dalvikvm(14884): threadid=1: thread exiting with uncaught exception (group=0x400259f8) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): FATAL EXCEPTION: main 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.b00348312.workout/com.b00348312.workout.WorkoutProgress}: android.database.sqlite.SQLiteException: near "tableacts": syntax error: create tableacts (id2integer primary key autoincrement, datetext not null,steps text not null, calories text not null); 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at android.app.ActivityThread.access$2300(ActivityThread.java:135) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at android.os.Handler.dispatchMessage(Handler.java:99) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at android.os.Looper.loop(Looper.java:144) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at android.app.ActivityThread.main(ActivityThread.java:4937) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at java.lang.reflect.Method.invokeNative(Native Method) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at java.lang.reflect.Method.invoke(Method.java:521) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at dalvik.system.NativeStart.main(Native Method) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): Caused by: android.database.sqlite.SQLiteException: near "tableacts": syntax error: create tableacts (id2integer primary key autoincrement, datetext not null,steps text not null, calories text not null); 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1817) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at com.b00348312.workout.DataBaseHelper$DatabaseHelper.onCreate(DataBaseHelper.java:60) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at com.b00348312.workout.DataBaseHelper.open(DataBaseHelper.java:78) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at com.b00348312.workout.WorkoutProgress.onCreate(WorkoutProgress.java:25) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751) 04-03 14:31:25.566: ERROR/AndroidRuntime(14884): ... 11 more

Upvotes: 1

Views: 104

Answers (1)

user
user

Reputation: 87064

Leave some spaces in the string where you declare the database creation string(probably in the onCreate method of the SQLiteOpenHelper):

id2integer primary key autoincrement, datetext not null,steps text not null, calories text not null

Check the String above and put some spaces after id2 and date(the first and second column of the database table).

Upvotes: 3

Related Questions