我的資產文件夾中有一個.png文件,我試圖在點擊屏幕時將該圖像顯示在屏幕上。爲什麼我的代碼中出現「資產未找到」錯誤?
InputStream open = null;
try{
open = asset.open("ic_launcher.png");
Bitmap bitmap = BitmapFactory.decodeStream(open);
ImageView image = (ImageView)findViewById(R.id.imageView1);
image.setImageBitmap(bitmap);
}catch(Exception e){
e.printStackTrace();
}
finally{
if(open != null){
try{
open.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
但我一直得到FileNotFoundException
,不知道爲什麼。
到底在哪'ic_launcher.png'放? – gunar
我的項目的'assets'文件夾。 –
is ic_launcher.png存儲在assets.put中您的完整代碼。初始化資產 –