Reputation: 39
//posense is a directory in the Android hardware device and there are some pictures in the directory
ImageView image1, image2;
File imagedirectory;
File[] imagepool;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image1 = (ImageView)findViewById(R.id.imageView1);
imagedirectory = new File("/posense");
imagepool = imagedirectory.listFiles();
image1.setImageResource(imagepool[1]); //this line is giving me an error
}
How can I solve this problem?
Upvotes: 0
Views: 332
Reputation: 430
Try these lines instead of imagedirectory = new File("/posense");
:
String path = Environment.getExternalStorageDirectory().getName() + File.separatorChar + "posense";
imagedirectory = new File(path);
image1.setImageURI(Uri.fromFile(imagepool[1]));
Upvotes: 0
Reputation: 1508
Use this instead:
image1.setImageURI(Uri.fromFile(imagepool[1]));
Documentation to be found here: setImageURI and fromFile.
Also, be aware that imagepool[1]
is the second element in the array, not the first.
Upvotes: 1