Android 获取从SQLite到ListView的位图

Android 获取从SQLite到ListView的位图,android,sqlite,listview,bitmap,Android,Sqlite,Listview,Bitmap,我试图在android应用程序上显示来自SQLite的个人资料联系人图像,但它不起作用,并且在出现的图像上崩溃。setImageBitmap(位图)。NullPointerException,我不知道为什么 如果有人能帮我。这是我的代码: public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); DatabaseHandler helper = new DatabaseHan

我试图在android应用程序上显示来自SQLite的个人资料
联系人
图像,但它不起作用,并且在出现
图像上崩溃。setImageBitmap(位图)
。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();
}

它抛出
nullPointerException
因为方法
BitmapFactory.decodeByteArray(bb,0,bb.length)
返回
NULL
到位图。

您正在模拟器或设备中测试应用程序?在尝试使用findViewById()方法之前,必须调用setContentView(R.layour.yourLayourLayout),如果您的(图像)为NULL,,,ie应该在setContentView中传递布局,其中imageView id使用R.id.profile\u pictureon emulator,这很重要吗?在我想在设备上测试之后。另一件重要的事情是,我正在使用ListActivity,因为我知道
R.id.profile\u图片
项目视图中,所以您在当前活动中找不到它。创建
自定义适配器
并在
getView