1

I have problem with decode stream. I'm trying to put images from folder /MyApp/icons to imageView. I have a fatal error

05-11 22:21:22.319: E/BitmapFactory(7981): Unable to decode stream: java.io.FileNotFoundException: /MyWeather/icons/a04n.png: open failed: ENOENT (No such file or directory)

I tried set a "icons/.." , "/icons/.." and a lot of another options, but anyone not works.

public class Notifications extends Activity{



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notification);

        ImageView imageView1 = (ImageView) findViewById(R.id.imageView1);
        Bundle extras = getIntent().getExtras();
        String ikona = extras.getString("icon");

        Bitmap bm = BitmapFactory.decodeFile("MyWeather/icons/a"+ikona+".png");
        imageView1.setImageBitmap(bm);

    }

}

Could anyone tell me, how I can get this icon from this folder and set it in my imageView? Thanks. enter image description here

Algeroth
  • 785
  • 3
  • 12
  • 29

1 Answers1

2

Put your folder in the root of project doesn't means it will put that folder to the root of your Android device...
Well, in your case, I suggest you to save files in assets folder and use AssetManager to load the file.

Here is example:

Put your "icons" folder into assets folder.

Use the following code to decode your image file:

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.notification);

    ImageView imageView1 = (ImageView) findViewById(R.id.imageView1);
    Bundle extras = getIntent().getExtras();
    String ikona = extras.getString("icon");

    AssetManager assetManager = getAssets();
    Bitmap bm;
    try {
        InputStream is = assetManager.open("icons/a"+ikona+".png");
        bm = BitmapFactory.decodeStream(is);    
    } catch (IOException e) {
        e.printStackTrace();
        // put your exception handling code here.
    }
    imageView1.setImageBitmap(bm);
}
chartsai
  • 368
  • 3
  • 7
  • /MyWeather/icons/a04n.png for example. – Algeroth May 11 '14 at 20:33
  • Are you sure? Your log shows that the file doesn't exist...Or maybe you have permission problem for the file, Have you tried chmod o+x /MyWeather/icons/a04n.png in adb shell? – chartsai May 11 '14 at 20:37