java - BitmapFactory 无法在 Android 中解码流 : java. io.FileNotFoundException

标签 java android database image

我试图从我的在线数据库中获取图片,在我的表中的数据字段“imagelink”中,我将我上传的图片的 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)

这是我在 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 );
}

关于java - BitmapFactory 无法在 Android 中解码流 : java. io.FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28391597/

相关文章:

android - 在whatsapp android中标记一个词

android - 尝试序列化包含 android 包的对象时出现 java.io.NotSerializedException : android. os.Bundle

database - Cypher左外连接sql模拟

database - 在 Kubernetes 中运行数据库是一种反模式吗?

java - 垂直居中 ListView

java - 好的设计 : How use fields of superclass

java - Canvas 上的 Android Studio drawBitmap 不起作用

java - 如何避免 BeanCreationException : Could not autowire field error

java - 使用 customadapter 在 ListView 中重复的项目

mysql - 分层数据 - 嵌套集模型 : MySql