How to get multiple images to show up in this coverflow. I am getting null pointer exception and other problems. How to be able to load the images from the SD card, not knowing how many images are on the SD card? The number of images is not fixed. I was able to get one image to show up with no problems by using this code:
i.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/pic03.png"));
it loaded one image, the one specified from the SD card and made all the coverflow images as that one same image, pic03.png, about a dozen of the same one image filled the cover flow. that is great, however i wanted to load all of the images on the SD card. so each image fills each part of the coverflow, not one same image filling all of them.
totally lost here and tried to do this and got null pointer exception from the Logcat and wonder why? does anyone know how to get this to work?
here below is the code that i am working with to give you some idea: notice that it does work when loading one image from a specified address on the SD card. at least that part worked great, but multiple images?
// added this code inside the onCreate method to load the cursor with images only if the IS_PRIVATE column
// in the sqlite database is equal to the integer 1
String[] img = { MediaStore.Images.Media._ID };
imagecursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, img,
MediaStore.Images.Media.IS_PRIVATE + "='" + 1 +"'",null, MediaStore.Images.Media._ID + "");
image_column_index = imagecursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
count = imagecursor.getCount();
//-------------------------------------------------------------------
// ImageAdapter class is a nested class inside of the CoverFlowExample class
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private FileInputStream fis;
// originally earlier version of this app loaded images from the R.drawable folder like this
private Integer[] mImageIds = {
// R.drawable.pic01,
// R.drawable.pic02,
// R.drawable.pic03,
// R.drawable.pic04,
// R.drawable.pic05,
// R.drawable.pic06,
// R.drawable.pic07,
// R.drawable.pic08,
// R.drawable.pic09
};
//---------------------------------------------------------------------
// getView() method that is in the ImageAdapter class that extends the BaseAdapter class
// this class is a nested class inside the CoverFlowExample class that extends Activity.
// the CoverFlowExample class is used to implement the coverflow part of the app as an Activity
public View getView(int position, View convertView, ViewGroup parent) {
// to load from resources like SD card
ImageView i = new ImageView(mContext);
// use for single image --> i.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/pic03.png"));
image_column_index = imagecursor.getColumnIndexOrThrowMediaStore.Images.Media.DATA);
imagecursor.moveToPosition(position);
int id = imagecursor.getInt(image_column_index);
i.setImageURIUri.withAppendedPathMediaStore .Images.Media.EXTERNAL_CONTENT_URI, ""+ id));
// image from R.drawable use --> i.setImageResource(mImageIds[position]);
i.setLayoutParams(new CoverFlow.LayoutParams(130, 130));
i.setScaleType(ImageView.ScaleType.MATRIX);
return i;
// return mImages[position]; <-- not using this as im am not getting image from R.drawable
}
The problem seems that String[] img = { MediaStore.Images.Media._ID }
this is the only column contained in the imagecursor
, while you try to get the DATA
column ,imagecursor.getColumnIndexOrThrowMediaStore.Images.Media.DATA)