我无法从SQLite数据库中检索存储为blob的图像。我正在使用Parcel。以下是我的代码。我想在imageView中显示名为galerie_foto_retrieve
的图像。现在该应用程序显示错误。我无法运行它。我是android的初学者,所以你有任何想法,我做错了什么。我将不胜感激任何帮助!
的DataProvider
private byte[] byteArray;
public DataProvider(byte[] byteArray)
this.byteArray=byteArray;
protected DataProvider(Parcel in)
{
byteArray = new byte[in.readInt()];
in.readByteArray(byteArray);
}
@Override
public void writeToParcel(Parcel dest, int flags)
{
dest.writeInt(byteArray.length);
dest.writeByteArray(byteArray);
}
DataListActivity
if (cursor.moveToFirst())
{
do {byte[] byteArray;
byteArray = cursor.getBlob(210);
DataProvider dataProvider = new DataProvider(byteArray);
}while (cursor.moveToNext());
}
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(DataListActivity.this, RetrieveData.class);
intent.putExtra("data", (DataProvider) listDataAdapter.getItem(position));
startActivity(intent);
}
});
检索数据
byte[] byteArray;
ImageView galerie_foto_retrieve;
Bundle bundle = getIntent().getExtras();
if (bundle!=null){
DataProvider dataProvider = bundle.getParcelable("data");
Bitmap b = BitmapFactory.decodeByteArray(byteArray , 0, byteArray.length);
galerie_foto_retrieve.setImageBitmap(b);
DbOperace
public Cursor getInformations(SQLiteDatabase db)
{
Cursor cursor;
String[] projections = {
FormDatabase.FormularovaDatabaze.IMAGE1
};
cursor = db.query(FormDatabase.FormularovaDatabaze.TABLE_NAME,projections,null,null,null,null,null);
if (cursor != null) {
cursor.moveToFirst();
return cursor;
}
else
{
return cursor;
}
答案 0 :(得分:0)
我已经弄明白了!我的错误在于文件检索数据 这是正确的解决方案,如果有人想知道
SELECT
pcr.PersonnelID, pcr.CourseID, lpc.CompletionDate
FROM
qryPersonnelCourseRequirements AS pcr
LEFT JOIN
LnkPersonnelCourses AS lpc On
(pcr.CourseID = lpc.CourseID) AND (pcr.PersonnelID = lpc.PersonnelID );