BitmapFactory 无法解码流:Android 中的 java.io.FileNotFoundException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28391597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
BitmapFactory unable to decode stream: java.io.FileNotFoundException in Android
提问by Jess Ian Sefulan
I'm trying to get pictures from my database online, in my "imagelink" which is datafield in my table, I put there the url of the pictures I uploaded, but unfortunately it gives me this error.
我正在尝试从我的数据库在线获取图片,在我的表中数据字段的“图像链接”中,我将上传的图片的 url 放在那里,但不幸的是它给了我这个错误。
02-08 15:05:29.432 14364-14364/com.example.jithea.testlogin E/BitmapFactory﹕ Unable to decode stream: java.io.FileNotFoundException: /http:/agustiniancampusevents.site40.net/newsDB/images/Visual%20Report%20Filipino%20Final-12%20copy.JPG: open failed: ENOENT (No such file or directory)
Here's my code in onPostExecute:
这是我在 onPostExecute 中的代码:
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
NewsActivity.this, productsList,
R.layout.news_list_item, new String[]{TAG_PID, TAG_IMAGELINK,
TAG_NEWSTITLE, TAG_DESCRIPTION},
new int[]{R.id.pid, R.id.imageView, R.id.newstitle, R.id.description});
// updating listview
setListAdapter(adapter);
}
});
}
采纳答案by Qualtagh
Use BitmapFactory.decodeStream
instead of BitmapFactory.decodeFile
.
使用BitmapFactory.decodeStream
代替BitmapFactory.decodeFile
。
try ( InputStream is = new URL( file_url ).openStream() ) {
Bitmap bitmap = BitmapFactory.decodeStream( is );
}