Reputation: 57
I'm developing an app for Android, I'm using the Gallery widget, and I've resized it to fullscreen mode, so it displays one image at a time.
<com.example.librosapp.MyGallery
android:id="@+id/examplegallery" android:layout_width="1920px"
android:layout_height="1020px"
android:padding="0px"
android:layout_marginTop="-20px"
/>
And here is a part of my Activity's code:
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imgView = new ImageView(cont);
//Here are my changes:
File imgFile = new File("sdcard/Libreria/0/0/0.JPG");
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
//The app runs OK til here:
imgView.setImageBitmap(myBitmap);
//BOOM! Exception
}
imgView.setLayoutParams(new MyGallery.LayoutParams(1950, 1000));
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
return imgView;
}
I don't know which exception am I getting, because I can't debug here, I'm using the .APK in my device. (The only way that I have to debug this, is with the virtual device, and I donnow why it runs really slow.
Am I doing something wrong?, that code works perfect if I use the same image, but as a project Resource (using setImageDrawable)
Upvotes: 3
Views: 4842
Reputation: 925
This is happening because myBitMap
is null. myBitMap
is null because the file path is invalid. My guess would be the file path should be /sdcard/Libreria/0/0/0.JPG
Upvotes: 1