AssetManager and InputStream for ImageView

This is the part of my function that assigns an image to my ImageView. I can not get it to show an image. I have my files listed under assets/signs/"image names." This code came straight from my textbook with some minor tweaks to fit my code. I appreciate the help.

String nextImage = signNames.remove(0);
AssetManager assets = getAssets();
InputStream stream;
         stream ="signs/"+nextImage + ".gif");
         Drawable sign = Drawable.createFromStream(stream,nextImage +".gif" );
    catch(IOException e){
         Log.e(TAG, "Error loading " +nextImage, e);


I think there is a much simpler idiom for what you are trying to do. No need to stream the image the want to display. Simply put the image in res/drawable (or res/drawable-hdpi, etc). Then simply:


Of if you need to get the resource from a dynamic string:

int id = getResources().getIdentifier("yourpackagename:drawable/" + nextImage, null, null);

see here

This assumes your signImageView is indeed an ImageView.

Need Your Help

Free geo data class library in C++ (Lat / Lng / distance / conversions)

c++ geolocation geocoding geospatial class-library

I am looking for a free geo data class library. I need to convert different formats of Latitude / Longitude values (e.g as here), get distances between lat/lng values, coordinates in range, etc.

aspnet5 rc1 access session outside controller

session controller httpcontext

In .Net Framework 4.5 code, System.Web.HttpContext.Current is used,