Reputation: 785
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.
Upvotes: 1
Views: 2106
Reputation: 368
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);
}
Upvotes: 2