Why does my SQL database not work in Android?
Posted
by
user1426967
on Stack Overflow
See other posts from Stack Overflow
or by user1426967
Published on 2012-05-31T16:29:52Z
Indexed on
2012/05/31
16:40 UTC
Read the original article
Hit count: 167
In my app a click on an image button brings you to the gallery. After clicking on an image I want to call onActivityResult to store the image path. But it does not work. In my LogCat it always tells me that it crashes when it tries to save the image path.
Can you find the problem?
My onActivityResult method:
mImageRowId = savedInstanceState != null ? savedInstanceState.getLong(ImageAdapter.KEY_ROWID) : null;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == PICK_FROM_FILE && data != null && data.getData() != null) {
Uri uri = data.getData();
if(uri != null) {
Cursor cursor = getContentResolver().query(uri, new String[] {
android.provider.MediaStore.Images.ImageColumns.DATA},
null, null, null);
cursor.moveToFirst();
String image = cursor.getString(0);
cursor.close();
if(image != null) {
// HERE IS WHERE I WANT TO SAVE THE IMAGE. HERE MUST BE THE ERROR!
if (mImageRowId == null) {
long id = mImageHelper.createImage(image);
if (id > 0) {
mImageRowId = id;
}
}
// Set the image and display it in the edit activity
Bitmap bitmap = BitmapFactory.decodeFile(image);
mImageButton.setImageBitmap(bitmap);
}
}
}
}
This is my onSaveInstanceState method:
private static final Long DEF_ROW_ID = 0L;
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putLong(ImageAdapter.KEY_ROWID, mImageRowId != null ? mImageRowId : DEF_ROW_ID);
super.onSaveInstanceState(outState);
}
This is a part from my DbAdapter:
public long createImage(String image) {
ContentValues cv = new ContentValues();
cv.put(KEY_IMAGE, image);
return mImageDb.insert(DATABASE_TABLE, null, cv);
}
© Stack Overflow or respective owner