Categories
Development Programming & Design

Load image from server using glide

//link from website

private String imageUrls[]= {
        "https://dicodingacademy.blob.core.windows.net/eventimages/dsc_chapter_stmik_stikom_indonesia_introducing_developer_student_club_and_google_technologies_logo_041019113915.png",
        "https://dicodingacademy.blob.core.windows.net/eventimages/dsc_ueu_event_workshop_4_flutter_aej_build_your_first_app_with_flutter_fetching_data_from_an_api_logo_151019182429.JPG",
        "https://dicodingacademy.blob.core.windows.net/eventimages/build_your_own_startup_for_a_better_generation_logo_270919142930.png",
        "https://dicodingacademy.blob.core.windows.net/eventimages/fundamental_unity_engine_logo_280919221953.png",
        "https://dicodingacademy.blob.core.windows.net/eventimages/colosseum_2019_x_dsc_ithb_ui_ux_design_mobile_app_prototyping_with_figma_logo_141019071945.png",
        "https://dicodingacademy.blob.core.windows.net/eventimages/make_unit_testing_great_again_logo_141019104313.jpg",
};

public RecyclerViewAdapter(Context context, ArrayList list) {
    this.context = context;
    this.mData = list;
}

public class ViewHolder extends RecyclerView.ViewHolder {

    public TextView tvNama, tvSource, tvSummary;
    public ImageView img;


    public ViewHolder(View v) {
        super(v);
        tvNama = v.findViewById(R.id.name);
        tvSource = v.findViewById(R.id.oleh);
        tvSummary = v.findViewById(R.id.summary);
        img = v.findViewById(R.id.img1);

    }
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_main_list, parent, false);
    ViewHolder vh = new ViewHolder(v);
    return vh;
}
// this is my viewHolder
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    holder.tvNama.setText("Nama : " + mData.get(position).getName());
    holder.tvSource.setText("" + mData.get(position).getOwner_name());
    holder.tvSummary.setText("" + mData.get(position).getSummary());

    //i don't know how to edit this
Glide
            .with(context)
            .load(mData.get(position).getImage())
            .into(holder.img);
}

@Override
public int getItemCount() {
    return mData.size();
}

please help, i want to load image from that urls but it always force close. i don’t understand how to do it.

  • I have searched on stackoverflow,google, youtube etc but i still don’t understand
  • I’m new on programming

Logcats:

10-18 07:08:04.888 28578-28578/com.example.projectbesar E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.projectbesar, PID: 28578
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.projectbesar/com.example.projectbesar.MainActivity}: java.lang.IllegalArgumentException: Unable to create converter for class com.example.projectbesar.ModelBiodata
        for method ApiRetrofitInterface.getData
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2684)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2750)
        at android.app.ActivityThread.access$1100(ActivityThread.java:186)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1606)
        at android.os.Handler.dispatchMessage(Handler.java:111)
        at android.os.Looper.loop(Looper.java:238)
        at android.app.ActivityThread.main(ActivityThread.java:6006)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:937)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:798)
     Caused by: java.lang.IllegalArgumentException: Unable to create converter for class com.example.projectbesar.ModelBiodata
        for method ApiRetrofitInterface.getData
        at retrofit2.Utils.methodError(Utils.java:52)
        at retrofit2.HttpServiceMethod.createResponseConverter(HttpServiceMethod.java:115)
        at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:82)
        at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:37)
        at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170)
        at retrofit2.Retrofit$1.invoke(Retrofit.java:149)
        at java.lang.reflect.Proxy.invoke(Proxy.java:393)
        at $Proxy0.getData(Unknown Source)
        at com.example.projectbesar.MainActivityPresenter.getData(MainActivityPresenter.java:46)
        at com.example.projectbesar.MainActivity.onCreate(MainActivity.java:28)
        at android.app.Activity.performCreate(Activity.java:6466)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2637)
            ... 9 more
     Caused by: java.lang.SecurityException: Can't make method constructor accessible
        at java.lang.reflect.Constructor.setAccessible(Constructor.java:336)
        at com.google.gson.internal.ConstructorConstructor.newDefaultConstructor(ConstructorConstructor.java:101)
        at com.google.gson.internal.ConstructorConstructor.get(ConstructorConstructor.java:83)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:99)
        at com.google.gson.Gson.getAdapter(Gson.java:423)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100)
        at com.google.gson.Gson.getAdapter(Gson.java:423)
        at com.google.gson.internal.bind.ArrayTypeAdapter$1.create(ArrayTypeAdapter.java:48)
        at com.google.gson.Gson.getAdapter(Gson.java:423)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100)
        at com.google.gson.Gson.getAdapter(Gson.java:423)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100)
        at com.google.gson.Gson.getAdapter(Gson.java:423)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory

well this is my model class , i think there something with it.
Model:
package com.example.projectbesar;

import java.util.ArrayList;

public class ModelBiodata {
        private String success;
        private ArrayList<Data> data;
    }

    public String getSuccess() {
            return success;
        }

        public void setSuccess(String success) {
            this.success = success;
        }

        public ArrayList<Data> getData() {
            return data;
        }

        public void setData(ArrayList<Data> data) {
            this.data = data;
        }
}

Leave a Reply

Your email address will not be published. Required fields are marked *