Java – RecyclerView does not have an adapter provisioned

RecyclerView does not have an adapter provisioned… here is a solution to the problem.

RecyclerView does not have an adapter provisioned

I have three Recycle Bin Views in one fragment. I’ve set up adapters for two of them. However, one recycler View will exaggerate the card View, while the other will not.

I debugged the code and the recycler that doesn’t show the View adapter isn’t called.

This is my onViewCreated() method in the fragment

public void onViewCreated(View view, @NonNull Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

recyclerViewVendors = view.findViewById(R.id.rcyview_vendors);
        recyclerViewEvents = view.findViewById(R.id.rcyview_home_events);
        String json;
        try{

InputStream is = getActivity().getAssets().open("vendorServices.json");
            int size = is.available();
            byte[] buffer = new byte[size];
            if(is.read(buffer) == -1){
                throw new EOFException();
            }
            is.close();
            json = new String(buffer, StandardCharsets.UTF_8);

JSONObject object = new JSONObject(json);
            JSONArray j_Array = object.getJSONArray("vendorServices");

for(int i=0; i<j_Array.length(); i++){
                JSONObject jo_inside = j_Array.getJSONObject(i);
                myDatasetVendors.add(new VendorService(
                        jo_inside.getString("name"),
                        jo_inside.getString("img")
                ));
            }

is = getActivity().getAssets().open("activities.json");
            size = is.available();
            buffer = new byte[size];
            if (is.read(buffer) == -1) {
                throw new EOFException();
            }

is.close();
            json = new String(buffer, StandardCharsets.UTF_8);

JSONObject obj = new JSONObject(json);
            JSONArray m_jArray = obj.getJSONArray("Activities");

for (int i = 0; i < m_jArray.length(); i++) {
                JSONObject jo_inside = m_jArray.getJSONObject(i);
                myDatasetEvents.add(jo_inside.getString("title"));
            }

} catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }

layoutManagerVendors = new LinearLayoutManager(this.getContext(), LinearLayoutManager.HORIZONTAL, false);
        recyclerViewVendors.setLayoutManager(layoutManagerVendors);

mAdapterVendors = new AdapterVendorServices(myDatasetVendors, this.getContext());
        recyclerViewVendors.setAdapter(mAdapterVendors);

layoutManagerEvents = new LinearLayoutManager(this.getContext(), LinearLayoutManager.HORIZONTAL, false);
        recyclerViewEvents.setLayoutManager(layoutManagerEvents);

mAdapterEvents = new AdapterHomeEvents(myDatasetEvents, this.getContext());
        recyclerViewEvents.setAdapter(mAdapterEvents);
    }

This is my adapter and it is not called

public class AdapterHomeEvents extends RecyclerView.Adapter<AdapterHomeEvents.MyViewHolder> {
    ArrayList<String> mDataset;
    Context context;

public AdapterHomeEvents(ArrayList<String> mDataset, Context context) {
        this.mDataset = mDataset;
        this.context = context;
    }

@NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.card_view_home_events, parent, false);
        MyViewHolder vh = new MyViewHolder(v);
        return vh;
    }

@Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.textView.setText(mDataset.get(position));
    }

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

static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView textView;

MyViewHolder(View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.txt_crdViewHome_events);
        }
    }
}

I want it to populate my two recycle Views with the card View, but it only populates one Recycler View and not the other.

Related Problems and Solutions