0

我的项目我正在从相机应用程序捕获图像并使用以下代码在列表视图中显示图像。MySimpleCursorAdapter:

public class MySimpleCursorAdapter extends SimpleCursorAdapter {

    public MySimpleCursorAdapter(Context context, int layout, Cursor c,
        String[] from, int[] to) {
        super(context, layout, c, from, to);
    }

    @Override
    public void setViewImage(ImageView image_v, String id) {

        String path = id;
        Bitmap b = BitmapFactory.decodeFile(path);
        image_v.setImageBitmap(resizedBitmap);

    }

}

列表.java

String[] from = new String[]{DbManager.babyName, DbManager.baby_image}; 
        int[] to = new int[] {/*R.id.list_id,*/ R.id.drname12,R.id.imageView1};//,R.id.list_date};{                 
        MySimpleCursorAdapter   Adapter = new MySimpleCursorAdapter(this, R.layout.rowlayout, c1, from, to);       
        list.setAdapter(Adapter);

到目前为止,一切都运行良好但是当我尝试使用这段代码调整位图大小时

 Bitmap resizedBitmap = Bitmap.createScaledBitmap(b, 200, 200, true);

它给出以下错误:

05-22 07:13:07.562: E/AndroidRuntime(478): FATAL EXCEPTION: main
05-22 07:13:07.562: E/AndroidRuntime(478): java.lang.NullPointerException
05-22 07:13:07.562: E/AndroidRuntime(478):  at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:380)
05-22 07:13:07.562: E/AndroidRuntime(478):  at com.example.tottal.baby.care.MySimpleCursorAdapter.setViewImage(MySimpleCursorAdapter.java:22)
05-22 07:13:07.562: E/AndroidRuntime(478):  at android.support.v4.widget.SimpleCursorAdapter.bindView(SimpleCursorAdapter.java:143)
05-22 07:13:07.562: E/AndroidRuntime(478):  at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:256)
4

1 回答 1

2

错误在这里正确检查

 Bitmap b = BitmapFactory.decodeFile(path);

您的变量pathb可能为空。

检查这些变量不等于 null 然后使用它们。

于 2013-05-21T08:38:06.187 回答