BitmapFactory无法解码流:Android中的java.io.FileNotFoundException [英] BitmapFactory unable to decode stream: java.io.FileNotFoundException in Android
本文介绍了BitmapFactory无法解码流:Android中的java.io.FileNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从我的数据库在线获取图片,在我的imagelink中,这是我表格中的数据字段,我把那些我上传的图片的网址放在那里,但不幸的是它给了我这个错误。
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.
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)
这是我在onPostExecute中的代码:
Here's my code in 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);
}
});
}
推荐答案
使用 BitmapFactory.decodeStream
而不是 BitmapFactory.decodeFile
。
try ( InputStream is = new URL( file_url ).openStream() ) {
Bitmap bitmap = BitmapFactory.decodeStream( is );
}
这篇关于BitmapFactory无法解码流:Android中的java.io.FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文