2
votes

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)

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);
            }
        });

    }
1
show some code please!!AADProgramming
That would be because the file "/http:/agustiniancampusevents.site40.net/newsDB/images/Visual%20Report%20Filipino%20Final-12%20copy.JPG" doesn't exist. Are you passing a URL to a method that reads from files? (URLs are not files.)user253751
how to pass a url to a method that reads files?Jess Ian Sefulan

1 Answers

16
votes

Use BitmapFactory.decodeStream instead of BitmapFactory.decodeFile.

try ( InputStream is = new URL( file_url ).openStream() ) {
  Bitmap bitmap = BitmapFactory.decodeStream( is );
}