如何获取多张图像以显示在此封面中。我得到空指针异常和其他问题。如何能够从SD卡加载图像,不知道SD卡上有多少图像?图像数量不固定。我可以通过使用此代码来获得一个图像,没有任何问题展现出来:从SD卡中获取多张图像以显示在Coverflow中
它加载一个形象,一个从SD卡中指定并取得所有的CoverFlow图像作为一个相同的图像,PIC03大约十几张同样的图像填满了封面流。这非常棒,但是我想将所有图像加载到SD卡上。因此每张图片都会填充封面流的每个部分,而不是填充所有这些图片的同一张图片。
完全丢失在这里,并试图做到这一点,并从Logcat得到空指针异常,并想知道为什么?有谁知道如何让这个工作?
下面是我正在处理的代码给你一些想法: 注意到它从SD卡上的指定地址加载一个图像时可以工作。至少那部分工作很好,但多个图像?
// 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
}
别喊了!它会让你的问题更难读。他们发明了换档钥匙是有原因的。在所有CAPS中键入会使文本难以阅读,并且不会提高您获得答案的速度。 –
我的帖子中只有5个字全部大写,但由于您对包含所有大写字母的词很敏感,所以我相信其他人也是如此。预期的目的是通过强调某些要点而不是为了鼓励而使文本更清晰。但有些不同意,不够公平,如果这是我在这里的文化,我已经把这5个字改为小写。但是,由于通常是以这种方式写入SD卡,所以我将“SD”字卡留在大写字母上。无论如何谢谢你的评论。一直想改善我的沟通,并与这里的社区合作。 – Kevik
原始问题的90%是IN ALL CAPS,这是我发布我的评论时所指的。您可以检查编辑历史记录以确认。至于强调,这个网站支持** bold **和* italic *,以及'code formatting',这样做;没有必要为此目的输入CAPS。大写的“SD”是正确的,“SDK”或“IBM”或“MS-DOS”也是如此。 –