我正在尝试显示Contact
来自 android 应用程序的个人资料图片,SQLite
但它不起作用,并且在image.setImageBitmap(bitmap)
出现时崩溃.NullPointerException
,我不知道为什么。
如果有人可以帮助我,请。这是我的代码:
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
DatabaseHandler helper = new DatabaseHandler(this);
database = helper.getWritableDatabase();
Cursor data = database.query("amigos", fields, null, null, null, null, null);
data.moveToFirst();
dataSource = new SimpleCursorAdapter(this, R.layout.row_def, data, fields, new int[] {R.id.Nombre_Amigo, R.id.profile_picture});
Log.d("ListarContactos","Oncreate....data: "+data.toString());
while (!data.isAfterLast()){
byte[] bb = data.getBlob(data.getColumnIndex(DatabaseHandler.KEY_PIC_SQ));
Log.d("ListarContactos","Oncreate....bb: "+bb.toString());
ByteArrayInputStream inputStream = new ByteArrayInputStream(bb);
Log.d("ListarContactos","Oncreate....inputStream: "+inputStream.toString());
Bitmap bitmap = BitmapFactory.decodeByteArray(bb, 0, bb.length);
Log.d("ListarContactos","Oncreate....Bitmap: "+bitmap.toString());
ImageView image = (ImageView) findViewById(R.id.profile_picture);
image.setImageBitmap(bitmap);
Log.d("ListarContactos","Oncreate....image: "+image.toString());
}
Log.d("ListarContactos","Oncreate....datasource: "+dataSource.toString());
setListAdapter(dataSource);
Log.d("ListarContactos","Oncreate....despres del ListAdapter");
helper.close();
ListView view = getListView();
}