• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Unable to decode stream: java.io.FileNotFoundException

Kurniawan

Newbie
Hai, i have problem with my project. i use calling Json data but i found errror like this :
Code:
E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: beasiswa_timur.jpg: open failed: ENOENT (No such file or directory)
MainActivity.java
Java:
public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {
private String TAG = MainActivity.class.getSimpleName();
private ProgressDialog pDialog;
private ListView lv;
private static String url = "https://api.danaberkah.com/v1/home_fundings";
ArrayList<HashMap<String, String>> home_fundings;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    NavigationView navigationView = findViewById(R.id.nav_view);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
        this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

home_fundings = new ArrayList<>();
lv = (ListView) findViewById(R.id.list);

private class GetContacts extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Showing progress dialog
        pDialog = new ProgressDialog(MainActivity.this);
        pDialog.setMessage("Mohon bersabar...");
        pDialog.setCancelable(false);
        pDialog.show();
    }

    @Override
    protected Void doInBackground(Void... arg0) {
        HttpHandler sh = new HttpHandler();

        // Making a request to url and getting response
        String jsonStr = sh.makeServiceCall(url);
        String JsonStrDonasi = sh.makeServiceCall(donasi_url);
        String JsonStrWakaf = sh.makeServiceCall(wakaf_url);
        String JsonStrTentangKami = sh.makeServiceCall(about_url);
        String jsonStrSyaratKetentuan = sh.makeServiceCall(syaratKetentuanUrl);
        /*Log.e(TAG, "Response from url: " + jsonStr);*/

        /*Home Fundings*/
        if (jsonStr != null) {
            try {
                JSONArray data = new JSONArray(jsonStr);

                // looping through All Contacts
                for (int i = 0; i < data.length(); i++) {
                    JSONObject c = data.getJSONObject(i);
                    String id = c.getString("id");
                    String usr_photo = c.getString("usr_photo");
                    String org_name = c.getString("org_name");
                    String funding_image = c.getString("funding_image");
                    String title = c.getString("title");
                    String end_time = c.getString("end_time");
                    String collected_amount = c.getString("collected_amount");

                    // tmp hash map for single contact
                    HashMap<String, String> contact = new HashMap<>();
                    // adding each child node to HashMap key => value
                    contact.put("id", id);
                    contact.put("usr_photo", usr_photo);
                    contact.put("org_name", org_name);
                    contact.put("title", title);
                    contact.put("funding_image", funding_image);
                    contact.put("end_time", end_time);
                    contact.put("collected_amount", collected_amount);
                    // adding contact to contact list
                    home_fundings.add(contact);
                }
            } catch (final JSONException e) {
                Log.e(TAG, "Json parsing error: " + e.getMessage());
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(),
                                "Json parsing error: " + e.getMessage(),
                                Toast.LENGTH_LONG)
                                .show();
                    }
                });

            }
        }
else {
    Log.e(TAG, "Couldn't get json from server.");
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(getApplicationContext(),
                    "Couldn't get json from server. Check LogCat for possible errors!",
                    Toast.LENGTH_LONG)
                    .show();
        }
    });
}
 return null;
}
@Override
protected void onPostExecute(Void result) {
    super.onPostExecute(result);
    // Dismiss the progress dialog
    if (pDialog.isShowing())
        pDialog.dismiss();
                /*
                 *Updating parsed JSON data into ListView
                 */
    /*This HOme Fundings*/
    ListAdapter adapter = new SimpleAdapter(
            MainActivity.this, home_fundings,
            R.layout.list_item_home, new String[]{"usr_photo", "org_name",
            "funding_image", "title", "collected_amount","end_time"},
            new int[]{R.id.icon,
                    R.id.nama,
                    R.id.img_thumbnail,
                    R.id.judul_cardview,
                    R.id.terkumpul_cardview,
                    R.id.tersisa_cardview}
    );
    lv.setAdapter(adapter);
}
}
}
list_item_home.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <androidx.cardview.widget.CardView
        android:id="@+id/card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="4dp"
        android:layout_margin="4dp"
        card_view:cardElevation="3dp">

        <RelativeLayout
            android:id="@+id/top_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/linear1">
                <ImageView
                    android:id="@+id/icon"
                    android:layout_width="24dp"
                    android:layout_height="17dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="5dp"
                    android:src="@drawable/index"
                    android:layout_marginRight="10dp"
                    android:layout_marginBottom="10dp"
                    android:contentDescription="TODO"/>

                <TextView
                    android:id="@+id/nama"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="5dp"
                    android:layout_toRightOf="@+id/icon"
                    android:text="danaberkah.com"
                    android:textColor="@color/text_default"
                    android:textSize="13sp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/linear2"
                android:layout_below="@id/linear1">
                <ImageView
                    android:id="@+id/img_thumbnail"
                    android:layout_width="match_parent"
                    android:layout_height="180dp"
                    android:src="@drawable/beras_murah"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_marginEnd="0dp"
                    android:layout_marginRight="0dp"
                    android:scaleType="fitXY"/>
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/linear3"
                android:layout_below="@id/linear2">

                <TextView
                    android:id="@+id/judul_cardview"
                    android:layout_width="fill_parent"
                    android:layout_height="20dp"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="bottom"
                    android:textColor="@color/text_default"
                    android:textSize="14sp"
                    android:text="20 Beasiswa Untuk Indonesia Timur"
                    android:textStyle="bold" />
            </LinearLayout>

           <LinearLayout
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:id="@+id/linear4"
               android:layout_below="@id/linear3">
               <TextView
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:text="Telah Terkumpul Rp."/>

               <TextView
                   android:id="@+id/terkumpul_cardview"
                   android:layout_width="fill_parent"
                   android:layout_height="20dp"
                   android:layout_centerHorizontal="true"
                   android:layout_gravity="bottom"
                   android:layout_marginLeft="8dp"
                   android:layout_marginTop="5dp"
                   android:text="129.000"
                   android:textSize="14sp"
                   android:textColor="@color/text_default"/>
           </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/linear5"
                android:layout_below="@id/linear4">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Berakhir Pada Tanggal : "/>

                <TextView
                    android:id="@+id/tersisa_cardview"
                    android:layout_width="fill_parent"
                    android:layout_height="20dp"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="bottom"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="5dp"
                    android:text="21-02-2019"
                    android:textSize="14sp"
                    android:textColor="@color/text_default" />
            </LinearLayout>

        </RelativeLayout>
    </androidx.cardview.widget.CardView>

</RelativeLayout>
on the display only text data successfully called, but not with the image.

and i have this permission but still not function to display image
Code:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


Thanks ..
 
Print out usr_photo, see what value you get.

Java:
String usr_photo = c.getString("usr_photo");
Log.d(TAG,usr_photo);
 
Back
Top Bottom