Also folgendes Problem. Ich möchte mit einem Datenbank Adapter alle elemente ausgeben lassen und in eine list view schriben. Eigendlich einfach.
Hier der Code aus der main activity:
Log.i("fillList", "(2)");
mSutureCursor = mSDbHelper.fetchAllSuture();
Log.i("fillList", "(2.1)");
startManagingCursor(mSutureCursor);
String[] fromB = new String[]{DbAdapter_Suture.KEY_TITLE};
int[] toB = new int[]{R.id.text2} ;
SimpleCursorAdapter notesB =
new SimpleCursorAdapter(this, R.layout.row_suture, mSutureCursor, fromB, toB);
ListView Roter_Faden = (ListView) findViewById(R.id.pe_LV_020);
Roter_Faden.setAdapter(notesB);
So weit so gut. Wenn ich jetzt den App starte erscheint folgendes in der LogCat:
06-15 14:19:00.661: I/fillList(447): (2)
06-15 14:19:00.661: D/DbAdapter(447): fetchAllSuture
06-15 14:19:00.661: I/SqliteDatabaseCpp(447): sqlite returned: error code = 1, msg = no such table: suture, db=/data/data/de.constantin.presenter2/databases/data
06-15 14:19:00.681: D/AndroidRuntime(447): Shutting down VM
06-15 14:19:00.681: W/dalvikvm(447): threadid=1: thread exiting with uncaught exception (group=0x40014760)
06-15 14:19:00.703: E/AndroidRuntime(447): FATAL EXCEPTION: main
06-15 14:19:00.703: E/AndroidRuntime(447): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.constantin.presenter2/de.constantin.presenter2.Prez_Edit}: android.database.sqlite.SQLiteException: no such table: suture: , while compiling: SELECT _id, title FROM suture
06-15 14:19:00.703: E/AndroidRuntime(447): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.app.ActivityThread.access$500(ActivityThread.java:122)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.os.Handler.dispatchMessage(Handler.java:99)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.os.Looper.loop(Looper.java:132)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.app.ActivityThread.main(ActivityThread.java:4123)
06-15 14:19:00.703: E/AndroidRuntime(447): at java.lang.reflect.Method.invokeNative(Native Method)
06-15 14:19:00.703: E/AndroidRuntime(447): at java.lang.reflect.Method.invoke(Method.java:491)
06-15 14:19:00.703: E/AndroidRuntime(447): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
06-15 14:19:00.703: E/AndroidRuntime(447): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
06-15 14:19:00.703: E/AndroidRuntime(447): at dalvik.system.NativeStart.main(Native Method)
06-15 14:19:00.703: E/AndroidRuntime(447): Caused by: android.database.sqlite.SQLiteException: no such table: suture: , while compiling: SELECT _id, title FROM suture
06-15 14:19:00.703: E/AndroidRuntime(447): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:146)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:367)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:130)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1539)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1419)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1375)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1455)
06-15 14:19:00.703: E/AndroidRuntime(447): at de.constantin.presenter2.DbAdapter_Suture.fetchAllSuture(DbAdapter_Suture.java:95)
06-15 14:19:00.703: E/AndroidRuntime(447): at de.constantin.presenter2.Prez_Edit.fillList(Prez_Edit.java:141)
06-15 14:19:00.703: E/AndroidRuntime(447): at de.constantin.presenter2.Prez_Edit.fillLayout(Prez_Edit.java:125)
06-15 14:19:00.703: E/AndroidRuntime(447): at de.constantin.presenter2.Prez_Edit.onCreate(Prez_Edit.java:82)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.app.Activity.performCreate(Activity.java:4397)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
06-15 14:19:00.703: E/AndroidRuntime(447): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
06-15 14:19:00.703: E/AndroidRuntime(447): ... 11 more
Alles anzeigen
Jetzt noch den DbAdapter:
package de.constantin.presenter2;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DbAdapter_Suture {
public static final String KEY_TITLE = "title";
public static final String KEY_ROWID = "_id";
private static final String TAG = "sutureDbAdapter";
private DatabaseHelper mSDbHelper;
private SQLiteDatabase mSDb;
private static final String DATABASE_CREATE =
"create table suture (_id integer primary key autoincrement, "
+ "title text not null);";
private static final String DATABASE_NAME = "data";
private static final String DATABASE_TABLE = "suture";
private static final int DATABASE_VERSION = 2;
private final Context mCtx;
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS notes");
onCreate(db);
}
}
public DbAdapter_Suture(Context ctx) {
this.mCtx = ctx;
}
public DbAdapter_Suture open() throws SQLException {
mSDbHelper = new DatabaseHelper(mCtx);
mSDb = mSDbHelper.getWritableDatabase();
return this;
}
public void close() {
mSDbHelper.close();
}
public long createSuture(String title) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_TITLE, title);
return mSDb.insert(DATABASE_TABLE, null, initialValues);
}
public boolean deleteSuture(long rowId) {
return mSDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
}
public Cursor fetchAllSuture() {
Log.d("DbAdapter", "fetchAllSuture");
return mSDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE}, null, null, null, null, null);
}
public Cursor fetchSuture(long rowId) throws SQLException {
Cursor mCursor =
mSDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
KEY_TITLE}, KEY_ROWID + "=" + rowId, null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
public boolean updateSuture(long rowId, String title) {
ContentValues args = new ContentValues();
args.put(KEY_TITLE, title);
return mSDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
}
}
Alles anzeigen
Könnte mit einer sagen was ist falschen machen und was diese fehlermeldung bedeutet:
android.database.sqlite.SQLiteException: no such table: suture: , while compiling: SELECT _id, title FROM suture
Danke