Skip to content

create recycler view in fragment?

i want create a fragment and have inside a recycler view for show products …
but when i render it is show this error : RecyclerView: No adapter attached; skipping layout

below i copy my codes;

this code is for adapter class :

 private ArrayList<Products> ProductsList;
private Context context;

public Adapter(ArrayList<Products> productsList, Context context) {
    ProductsList = productsList;
    this.context = context;

public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(context).inflate(R.layout.row_layout, parent, false);
    return new MyHolder(v);

public void onBindViewHolder(MyHolder holder, final int position) {
    Products products = ProductsList.get(position);

    holder.txtPrice.setText("$ " + products.getPrice());
    Picasso.get().load(Config.ipValue + "/images/" + products.getPhoto()).into(holder.imgV);
    holder.imgV.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            v.startAnimation(AnimationUtils.loadAnimation(context, android


public int getItemCount() {
    return ProductsList.size();

class MyHolder extends RecyclerView.ViewHolder {

    TextView txtName;
    TextView txtPrice;
    ImageView imgV;

    public MyHolder(View itemView) {

        txtName = itemView.findViewById(;
        txtPrice = itemView.findViewById(;
        imgV = itemView.findViewById(;

and this one for web api class :

public class WebApiHandler {

Context context;
String apiLink = "";
ArrayList<Products> products = new ArrayList<>();

public WebApiHandler(Context context) {
    this.context = context;

void apiConnect(String type) {
    switch (type) {
        case "getproducts": {
            apiLink = Config.getProductsWebApi;

    ProgressDialog dialog =, "Connecting...",
            "please wait", false, false);
    StringRequest request = new StringRequest(Request.Method.POST,
            apiLink, new Response.Listener<String>() {
        public void onResponse(String response) {
    }, new Response.ErrorListener() {
        public void onErrorResponse(VolleyError error) {
    RequestQueue queue = Volley.newRequestQueue(context);

private void showJson(String response) {
    try {
        JSONObject jsonObject = new JSONObject(response);
        JSONArray jsonArray = jsonObject.getJSONArray("response");
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject object = jsonArray.getJSONObject(i);
            String id = object.getString("id");
            String name = object.getString("name");
            String description = object.getString("description");
            String price = object.getString("price");
            String photo = object.getString("photo");
            Products p = new Products(id, name, description, price, photo);
    } catch (JSONException e) {
    VerticalFragment.productsArrayList = products;
    IData iData = (IData) context;

and my fragment code :

public class VerticalFragment extends Fragment implements IData {

RecyclerView rcVertical;
WebApiHandler webApiHandler;
static ArrayList<Products> productsArrayList = new ArrayList<>();

public VerticalFragment() {

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_vertical, container, false);
    rcVertical = view.findViewById(;
    webApiHandler = new WebApiHandler(getContext());
    rcVertical.addOnItemTouchListener(new RecyclerTouchListener(getContext(), rcVertical,
            new RecyclerTouchListener.ClickListener() {
                public void onClick(View view, int position) {
                    ProductActivity.products = productsArrayList.get(position);
                    startActivity(new Intent(getContext(), ProductActivity.class));

                public void onLongClick(View view, int position) {


    return view;

public void sendData() {
    Adapter adapter = new Adapter(productsArrayList, getContext());
    rcVertical.setLayoutManager(new LinearLayoutManager((getContext())));
    rcVertical.setItemAnimator(new DefaultItemAnimator());

i should say i create a interface and have one method i say it sendData


This is a common error when there is no adapter attached to recyclerview upon showing recyclerview. It will not cause any harm to your app, but you could avoid it by setting empty adapter without data, and later when you get your data, provide it to your adapter and notify it

Edit – Example added

Create setter for your list in adapter. After that, in your fragment make adapter global and in onCreateView make instance of your adapter and attach it to recyclerview

adapter = new Adapter(new ArrayList<>(), getContext());
...Initialize recyclerview...

And then in your sendData interface put your loaded values in it