bekommen dies, wie ich SQLite-Daten von nicht Aktivitätsklasse speichern getApplicationContext()
kippt Reihe von SQLite
public class SaveInSQLiteContacts {
private Context context;
public SaveInSQLiteContacts(Context context){
this.context = context;
}
public void save(String name, String imageKey, String email, String phone, String uid){
SQLiteContacts sqLiteContacts = new SQLiteContacts(context);
SQLiteDatabase database = sqLiteContacts.getWritableDatabase();
ContentValues contentValues = new ContentValues();
byte [] image = null;
if(imageKey != null)
image = Base64.decode(imageKey, Base64.DEFAULT);
contentValues.put(SQLiteContacts.KEY_NAME, name);
contentValues.put(SQLiteContacts.KEY_IMAGE, image);
contentValues.put(SQLiteContacts.KEY_EMAIL, email);
contentValues.put(SQLiteContacts.KEY_PHONE, phone);
contentValues.put(SQLiteContacts.USERID, uid);
database.insert(SQLiteContacts.CONTACTS, null, contentValues);
sqLiteContacts.close();
}
}
verwenden und dies ist, wie I`m versucht, Daten zu erhalten, von ihm
private void checker(){
SQLiteContacts sqLiteContacts = new SQLiteContacts(getApplicationContext());
SQLiteDatabase database = sqLiteContacts.getWritableDatabase();
Cursor cursor = database.query(SQLiteContacts.CONTACTS, null, null, null, null, null, null);
if(cursor != null) {
if (cursor.moveToFirst()) {
int i = cursor.getColumnIndex(SQLiteContacts.KEY_ID);
int itemId = cursor.getColumnIndex(SQLiteContacts.KEY_NAME);
int fixerId = cursor.getColumnIndex(SQLiteContacts.USERID);
do {
int id = cursor.getInt(i);
String itemName = cursor.getString(itemId);
String fixerUID = cursor.getString(fixerId);
Log.d("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", itemName);
Log.d("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", fixerUID);
Log.d("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", String.valueOf(id));
} while (cursor.moveToNext());
}
}
cursor.close();
sqLite.close();
}
dies was ich bekomme nachher:
Failed to read row 0, column 0 from a CursorWindow which has 0 rows, 6 columns.
java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
was mache ich falsch?
aber I' Es wird kein Bild von dieser Cursor-Anforderung erhalten. –
Spalten - \t Zeichenfolge: Eine Liste der zurückzugebenden Spalten. Wenn Sie NULL übergeben, werden alle Spalten zurückgegeben. Es wird davon abgeraten, das Lesen von Daten aus dem Speicher zu verhindern, der nicht verwendet wird. – jeprubio
In den Spalten Parameter senden Sie null, so dass es alle Spalten zurückgibt, das Bild enthalten, und deshalb übertrifft es die 2MB. Wenn Sie das Bild nicht benötigen, fragen Sie einfach nach den Spalten, die Sie in diesem Parameter benötigen. – jeprubio