android – How I access asset folder?-ThrowExceptions

Exception or error:

I need to load image from assets in folder like this

my folder

and my code just check that how i can access my folder (sorry from poor coding)

  public Bitmap test3(){

Bitmap bitmap = null;
AssetManager assManager = null;
try {
    InputStream is ="train/c00/Astb412_400_30_18_161.bmp");
    bitmap = BitmapFactory.decodeStream(is);
    return bitmap;
} catch (Exception e) {

    return bitmap;

So, I just test debug to see but it didn’t work
test debug

I don’t know how I access file. please help

  • I should put my folder in res or asset which one is better?
  • Can I path folder by string path (I’ve tried it but didn’t work for me)
How to solve:

Better and most suitable way is to put your asset in res folder. After that you can assess them like this.

Drawable image = getResources().getDrawable(R.drawable.your_file_name_goes_here);

Leave a Reply

Your email address will not be published. Required fields are marked *