i want to display the stored images from folder AutoistDiary in sdcard into gallery, the activity starts in emulator in which i have wrote that code,but when i execute same apk on my device ,it lets force close,
here is my code,it through force close in actual device, what to do in such a case ?
//get the gallery view---------------------------------------------------------------------
Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this, SDCard()));
g.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
Log.i("position", Integer.toString(position));
}
});
}
private List<String> SDCard()
{
Log.i("inside", "SDCard() method");
List<String> tFileList = new ArrayList<String>();
File dir = Environment.getExternalStorageDirectory();
// File yourFile = new File(dir, "path/to/the/file/inside/the/sdcard.ext");
//It have to be matched with the directory in SDCard
File f = new File( dir, "/AutoistDiary/");
//File f = new File( "/sdcard/");
File[] files=f.listFiles();
for(int i=0; i<files.length; i++)
{
File file = files[i];
/*It's assumed that all file in the path
are in supported type*/
tFileList.add(file.getPath());
msg="getting autioistdiary file path" + i+tFileList;
showToastMessage(msg);
}
return tFileList;
}
public class ImageAdapter extends BaseAdapter
{
int mGalleryItemBackground;
private Context mContext;
private List<String> FileList;
public ImageAdapter(Context c, List<String> fList)
{
mContext = c;
FileList = fList;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground,0);
a.recycle();
}
public int getCount() {
return FileList.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView,
ViewGroup parent) {
ImageView i = new ImageView(mContext);
Bitmap bm = BitmapFactory.decodeFile(FileList.get(position).toString());
i.setImageBitmap(bm);
i.setLayoutParams(new Gallery.LayoutParams(100,70));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
Log.i("images ", "added to gallery from card");
msg="added to gallery from card";
showToastMessage(msg);
return i;
}
}
public TypedArray obtainStyledAttributes(int theme) {
// TODO Auto-generated method stub
return null;
}
here is my logcat 12-27 12:02:42.016: I/inside(1217): docsshow 12-27 12:02:42.056: D/szipinf(1217): Initializing inflate state 12-27 12:02:42.086: D/szipinf(1217): Initializing inflate state 12-27 12:02:42.216: I/inside(1217): SDCard() method 12-27 12:02:42.996: D/skia(1217): --- SkImageDecoder::Factory returned null 12-27 12:02:43.017: I/images(1217): added to gallery from card 12-27 12:02:43.866: D/skia(1217): --- SkImageDecoder::Factory returned null 12-27 12:02:43.886: I/images(1217):