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);
}
}
List.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)
是位 'B' 空? – Blackbelt
您是否嘗試過使用它之前記錄您的位圖'b'以查看它是否爲空? –
你的路徑變量爲null ... – Riser