ich versuche, eine Klasse zu erstellen, die den Inhalt einer Datenbank anzeigen wird, und ich habe Tutorial verwendet, um die Methode dafür zu finden. Nach dem Tutorial dachte ich, ich hätte eine Methode, um den Inhalt der Datenbank zu zeigen.Android-Klasse stürzt ab, nicht sicher, warum
hier ist die Klasse, die nicht funktioniert:
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 ich ein paar Dinge zu klären vergessen. Eine dieser Klassen wird nicht geöffnet und stürzt stattdessen die Anwendung ab. die logcat für diese Klasse ist hier
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
Bitte sagen Sie uns, was nicht funktioniert. Am besten ist es, den Stacktrace der Ausnahme in Logcat zu finden und hier zu posten. – Janusz
können Sie bitte Logcat einfügen? – Nikhil
Ihre create-Anweisung scheint falsch zu gehen? – Nanne