Ich habe eine Datenbank, die bereits eine Tabelle "LocalLogin" enthält und richtig eingestellt ist und problemlos abgefragt werden kann, wird eingerichtet genauso wie meine neue Tabelle "PersonList". Jedoch wenn ich versuche, eine Abfrage auf Person auszuführen einige Werte auszuwählen, erhalte ich die FehlerAndroid "android.database.sqlite.SQLiteException: keine solche Tabelle" Fehler beim Ausführen der Abfrage in der Datenbank
android.database.sqlite.SQLiteException: no such table: PersonList: , while compiling: SELECT ...
Es gibt mir die Idee, dass die Tabelle nicht erstellt wurde, obwohl ich eine erstellen Abfrage in der onCreate Methode meiner ausführen SQLiteOpenHelper-Klasse. Hat derselbe Datenbankname wie LocalLogin das mögliche Problem?
Hier ist der entsprechende Code:
Der Datenbank-Adapter Klasse
public class GoingOutPersonListDbAdapter {
private static final String DATABASE_NAME = "GoingOutData";
private static final String DATABASE_TABLE_PERSONLIST = "PersonList";
private static final int DATABASE_VERSION = 1;
public static final String PERSONLIST_ID = "PersonList_id";
public static final String PERSONLIST_LOGIN = "Login";
public static final String PERSONLIST_PASSWORD = "Password";
private static final String TAG = "Debugstring";
private PersonListDatabaseHelper mPersonListDbHelper;
private SQLiteDatabase mDb;
private static final String DATABASE_CREATE =
"CREATE Table " + DATABASE_TABLE_PERSONLIST+ " ("
+ PERSONLIST_ID + " integer PRIMARY KEY Autoincrement, "
+ PERSONLIST_LOGIN + " text NOT NULL,"
+ PERSONLIST_PASSWORD + " text NOT NULL);";
private final Context mCtx;
private static class PersonListDatabaseHelper extends SQLiteOpenHelper {
PersonListDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d(TAG,DATABASE_CREATE);
db.execSQL(DATABASE_CREATE);
}
}
public GoingOutPersonListDbAdapter(Context ctx) {
this.mCtx = ctx;
}
public GoingOutPersonListDbAdapter open() throws SQLException {
mPersonListDbHelper = new PersonListDatabaseHelper(mCtx);
mDb = mPersonListDbHelper.getWritableDatabase();
return this;
}
public Cursor searchPerson(String searchString) {
return mDb.query(DATABASE_TABLE_PERSONLIST, new String[] {PERSONLIST_ID, PERSONLIST_LOGIN, PERSONLIST_PASSWORD}, searchString, null, null, null, null);
}
}
In meiner Tätigkeit Klasse:
private GoingOutPersonListDbAdapter mPersonListDbHelper;
...
mPersonListDbHelper = new GoingOutPersonListDbAdapter(this);
mPersonListDbHelper.open();
...
//loginEditText is properly set
Cursor personList = mPersonListDbHelper.searchPerson(GoingOutPersonListDbAdapter.PERSONLIST_LOGIN + " = '" + loginEditText + "'");
startManagingCursor(personList);
Ich fügte hinzu, "\t \t @Override \t \t public void ONUPGRADE (SQLiteDatabase db, int oldversion, int newVersion) { \t \t \t db.execSQL (DATABASE_CREATE); \t \t}" und änderte die Datenbank Version 2, aber ich habe immer noch den gleichen Fehler –
Funktioniert wie ein Charme, erhöhte ich die Datenbank-Version in beiden Datenbank-Adapter, die ich anscheinend nicht getan haben sollte –
funktioniert gut für mich –