このカバーフローに複数の画像を表示する方法。nullポインタ例外やその他の問題が発生しています。SDカードに何枚の画像があるかわからないまま、SDカードから画像をロードできるようにするにはどうすればよいですか?画像の数は固定されていません。このコードを使用することで、問題なく1つの画像を表示することができました。
i.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/pic03.png"));
SDカードから指定された1つの画像をロードし、すべてのカバーフロー画像を同じ1つの画像pic03.pngとして作成し、同じ1つの画像の約12個がカバーフローを埋めました。それは素晴らしいことですが、SDカードにすべての画像をロードしたかったのです。したがって、各画像はカバーフローの各部分を埋めますが、1つの同じ画像がすべてを埋めるわけではありません。
ここで完全に失われ、これを実行しようとしましたが、Logcatからnullポインター例外が発生し、なぜだろうか?誰かがこれを機能させる方法を知っていますか?
以下は私があなたにいくつかのアイデアを与えるために使っているコードです:SDカードの指定されたアドレスから1つの画像をロードするときにそれが機能することに注意してください。少なくともその部分はうまく機能しましたが、複数の画像がありますか?
// 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
}