title: How can I display a fetched list from an API?
body: <p>I have a page on my app where im trying to display a list of <code>cars</code> and Im not sure if the issue is with my list code or my fetch code so ill try to put as much code as possible.</p>
  
  <p>Here is my <code>RelativeLayout</code> where I want the data to be displayed:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".CarList"&gt;
  
      &lt;androidx.recyclerview.widget.RecyclerView
          android:id="@+id/main_list"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>here is how I want my code to be displayed by fetched data:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/cars_List_items"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
  
  
          &lt;TextView
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:drawableStart="@drawable/ic_cars"
              android:drawableLeft="@drawable/ic_cars"
              android:drawablePadding="5dp"
              android:gravity="start"
              android:paddingLeft="16dp"
              android:paddingRight="16dp"
              android:text="Cars Sale"
              android:textSize="12sp" /&gt;
  
          &lt;TextView
              android:id="@+id/carDetailsDate"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:drawableEnd="@drawable/ic_history"
              android:drawableRight="@drawable/ic_history"
              android:drawablePadding="5dp"
              android:gravity="end"
              android:maxLength="10"
              android:maxLines="1"
              android:paddingLeft="16dp"
              android:paddingRight="16dp"
              android:textColor="@color/colorPrimary"
              android:textSize="12sp"
              tools:text="20/10/1999" /&gt;
  
  
  
      &lt;ImageView
          android:id="@+id/carDetailsImage"
          android:layout_width="145dp"
          android:layout_height="145dp"
          android:scaleType="fitXY"
          app:layout_constraintDimensionRatio="4:1"
          app:layout_constraintStart_toStartOf="parent"
          app:srcCompat="@drawable/car1" /&gt;
  
      &lt;TextView
          android:id="@+id/carDetailsTitle"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="16dp"
          android:layout_marginLeft="16dp"
          android:layout_marginTop="24dp"
          android:textSize="18sp"
          app:layout_constraintStart_toEndOf="@+id/carDetailsImage"
          app:layout_constraintTop_toTopOf="@+id/carDetailsImage"
          tools:text="Car1" /&gt;
  
      &lt;TextView
          android:id="@+id/carDetailsCategory"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="8dp"
          android:textSize="18sp"
          android:textStyle="bold"
          app:layout_constraintStart_toStartOf="@+id/carDetailsTitle"
          app:layout_constraintTop_toBottomOf="@+id/carDetailsTitle"
          tools:text="V1 208" /&gt;
  
      &lt;TextView
          android:id="@+id/carDetailsPrice"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAllCaps="true"
          android:textColor="@color/homepage_car"
          android:textSize="18sp"
          android:textStyle="bold"
          app:layout_constraintBottom_toBottomOf="@+id/carDetailsCategory"
          app:layout_constraintEnd_toEndOf="@+id/carDetailsYear"
          app:layout_constraintHorizontal_bias="0.93"
          app:layout_constraintStart_toEndOf="@+id/carDetailsCategory"
          app:layout_constraintTop_toTopOf="@+id/carDetailsCategory"
          tools:text="20000" /&gt;
  
      &lt;TextView
          android:id="@+id/carDetailsDistance"
          android:layout_width="wrap_content"
          android:layout_height="0dp"
          android:layout_marginBottom="8dp"
          android:drawableTop="@drawable/ic_km"
          android:gravity="bottom"
          android:paddingTop="22dp"
          android:textSize="14sp"
          app:drawableTint="@color/homepage_car"
          app:layout_constraintBottom_toBottomOf="@+id/carDetailsImage"
          app:layout_constraintEnd_toStartOf="@+id/cardetailsGear"
          app:layout_constraintStart_toEndOf="@+id/carDetailsImage"
          app:layout_constraintTop_toBottomOf="@+id/carDetailsCategory"
          tools:text="2000" /&gt;
  
      &lt;TextView
          android:id="@+id/cardetailsGear"
          android:layout_width="wrap_content"
          android:layout_height="0dp"
          android:drawableTop="@drawable/ic_motion_vector"
          android:gravity="bottom"
          android:paddingTop="22dp"
          android:textSize="14sp"
          app:drawableTint="@color/homepage_car"
          app:layout_constraintBottom_toBottomOf="@+id/carDetailsDistance"
          app:layout_constraintEnd_toStartOf="@+id/carDetailsOil"
          app:layout_constraintHorizontal_bias="0.5"
          app:layout_constraintStart_toEndOf="@+id/carDetailsDistance"
          app:layout_constraintTop_toTopOf="@+id/carDetailsDistance"
          tools:text="Automatic" /&gt;
  
      &lt;TextView
          android:id="@+id/carDetailsOil"
          android:layout_width="wrap_content"
          android:layout_height="0dp"
          android:drawableTop="@drawable/ic_fuel_type"
          android:gravity="bottom"
          android:paddingTop="22dp"
          android:textSize="14sp"
          app:drawableTint="@color/homepage_car"
          app:layout_constraintBottom_toBottomOf="@+id/cardetailsGear"
          app:layout_constraintEnd_toStartOf="@+id/carDetailsYear"
          app:layout_constraintHorizontal_bias="0.5"
          app:layout_constraintStart_toEndOf="@+id/cardetailsGear"
          app:layout_constraintTop_toTopOf="@+id/cardetailsGear"
          tools:text="Diesel" /&gt;
  
      &lt;TextView
          android:id="@+id/carDetailsYear"
          android:layout_width="wrap_content"
          android:layout_height="0dp"
          android:drawableTop="@drawable/ic_general_model"
          android:gravity="bottom"
          android:paddingTop="22dp"
          android:textSize="14sp"
          app:drawableTint="@color/homepage_car"
          app:layout_constraintBottom_toBottomOf="@+id/carDetailsOil"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.5"
          app:layout_constraintStart_toEndOf="@+id/carDetailsOil"
          app:layout_constraintTop_toTopOf="@+id/carDetailsOil"
          tools:text="2010" /&gt;
  
      &lt;TextView
          android:id="@+id/button"
          android:layout_width="0dp"
          android:layout_height="2dp"
          android:background="@color/colorPrimary"
          android:textSize="10sp"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/carDetailsImage" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Here is my <code>CarList</code> class where the fetch data code is:</p>
  
  <pre><code>public class CarList extends AppCompatActivity {
  
      private RecyclerView mList;
  
      private LinearLayoutManager linearLayoutManager;
      private DividerItemDecoration dividerItemDecoration;
      private List&lt;CarClass&gt; carClassList;
      private RecyclerView.Adapter adapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_car_list);
  
          mList = findViewById(R.id.main_list);
  
          carClassList = new ArrayList&lt;&gt;();
          adapter = new CarAdapter(getApplicationContext(), carClassList);
  
          linearLayoutManager = new LinearLayoutManager(this);
          linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
          dividerItemDecoration = new DividerItemDecoration(mList.getContext(), linearLayoutManager.getOrientation());
  
          mList.setHasFixedSize(true);
          mList.setLayoutManager(linearLayoutManager);
          mList.addItemDecoration(dividerItemDecoration);
          mList.setAdapter(adapter);
  
          getData();
      }
  
  
  
      private void getData() {
          JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(URL_CAR_LIST, null, new Response.Listener&lt;JSONObject&gt;() {
                      @Override
                      public void onResponse(JSONObject response) {
  
                          try {
                              JSONArray jsonArray = response.getJSONArray("listCar");
  
                              for (int i = 0; i &lt; jsonArray.length(); i++) {
                                  JSONObject jsonObject = jsonArray.getJSONObject(i);
  
                                  CarClass car = new CarClass();
                                  car.setTitle(jsonObject.getString("adTitle"));
                                  car.setDate(jsonObject.getString("adDate"));
                                  car.setPrice(jsonObject.getDouble("adPrice"));
                                  car.setCategory(jsonObject.getString("category"));
                                  car.setKilometer(jsonObject.getDouble("kilometer"));
                                  car.setModelYear(jsonObject.getString("modelYear"));
                                  car.setFuel(jsonObject.getString("fuelType"));
                                  car.setGear(jsonObject.getString("gearType"));
  
  //                                carClassList.add(car);
                              }
                          } catch (JSONException ex) {
                              ex.printStackTrace();
                          }
                      }
                  }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  Log.e("Volley", error.toString());
              }
          });
          RequestQueue requestQueue = Volley.newRequestQueue(this);
          requestQueue.add(jsonObjectRequest);
      }
  }
  
  </code></pre>
  
  <p>here is my <code>CarClass</code>:</p>
  
  <pre><code>public class CarClass {
      public String title;
      public String date;
      public Double price;
      public String category;
      public String brand;
      public String brandModel;
      public Double kilometer;
      public String modelYear;
      public String fuel;
      public String gear;
  
      public CarClass() {
  
      }
  
      public CarClass( String title, String date, Double price, String category,String brand, String brandModel, Double kilometer, String modelYear, String fuel, String gear) {
          this.title = title;
          this.date = date;
          this.price = price;
          this.category = category;
          this.brand = brand;
          this.brandModel = brandModel;
          this.kilometer = kilometer;
          this.modelYear = modelYear;
          this.fuel = fuel;
          this.gear = gear;
      }
  
      public String getTitle() {
          return title;
      }
  
      public void setTitle(String title) {
          this.title = title;
      }
  
      public String getDate() {
          return date;
      }
  
      public void setDate(String date) {
          this.date = date;
      }
  
      public Double getPrice() {
          return price;
      }
  
      public void setPrice(Double price) {
          this.price = price;
      }
  
      public String getCategory() {
          return category;
      }
  
      public void setCategory(String category) {
          this.category = category;
      }
  
      public String getBrand() {
          return brand;
      }
  
      public void setBrand(String brand) {
          this.brand = brand;
      }
  
      public String getBrandModel() {
          return brandModel;
      }
  
      public void setBrandModel(String brandModel) {
          this.brandModel = brandModel;
      }
  
      public Double getKilometer() {
          return kilometer;
      }
  
      public void setKilometer(Double kilometer) {
          this.kilometer = kilometer;
      }
  
      public String getModelYear() {
          return modelYear;
      }
  
      public void setModelYear(String modelYear) {
          this.modelYear = modelYear;
      }
  
      public String getFuel() {
          return fuel;
      }
  
      public void setFuel(String fuel) {
          this.fuel = fuel;
      }
  
      public String getGear() {
          return gear;
      }
  
      public void setGear(String gear) {
          this.gear = gear;
      }
  }
  </code></pre>
  
  <p>Here is my <code>CarAdapter</code>:</p>
  
  <pre><code>public class CarAdapter extends RecyclerView.Adapter&lt;CarAdapter.ViewHolder&gt;{
  
      private Context context;
      private List&lt;CarClass&gt;  list;
  
      public CarAdapter(Context context, List&lt;CarClass&gt; list) {
          this.context = context;
          this.list = list;
      }
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(context).inflate(R.layout.cars_list, parent, false);
          return new ViewHolder(v);
      }
  
      @Override
      public void onBindViewHolder(ViewHolder holder, int position) {
          CarClass car = list.get(position);
  
          holder.textDate.setText(car.getDate());
          holder.textTitle.setText(car.getTitle());
          holder.textCategory.setText(car.getCategory());
          holder.textPrice.setText(String.valueOf(car.getPrice()));
          holder.textKilometer.setText(String.valueOf(car.getKilometer()));
          holder.textGear.setText(car.getGear());
          holder.textFuel.setText(car.getFuel());
          holder.textYear.setText(car.getModelYear());
      }
  
      @Override
      public int getItemCount() {
          return list.size();
      }
  
      public class ViewHolder extends RecyclerView.ViewHolder {
          public TextView textDate, textTitle, textCategory, textPrice, textKilometer, textGear, textFuel, textYear;
  
          public ViewHolder(View itemView) {
              super(itemView);
  
              textDate = itemView.findViewById(R.id.carDetailsDate);
              textTitle = itemView.findViewById(R.id.carDetailsTitle);
              textCategory = itemView.findViewById(R.id.carDetailsCategory);
              textPrice = itemView.findViewById(R.id.carDetailsPrice);
              textKilometer = itemView.findViewById(R.id.carDetailsDistance);
              textGear = itemView.findViewById(R.id.cardetailsGear);
              textFuel = itemView.findViewById(R.id.carDetailsOil);
              textYear = itemView.findViewById(R.id.carDetailsYear);
          }
      }
  
  }
  </code></pre>
  
  <p>I cant tell if the error is from my code or if something is missing in my <code>fetch</code> code?</p>
  
  <p>And last but not least here is what my debugger shows when I open the activity:</p>
  
  <pre><code>D/Volley: [1453] BasicNetwork.logSlowRequests: HTTP response for request=&lt;[ ] "#MyAPILInk" 0x5557fcc5 NORMAL 1&gt; [lifetime=8506], [size=3841], [rc=200], [retryCount=1]
  </code></pre>
  
  <p>Here is what the <code>logcat</code> shows:</p>
  
  <pre><code>2020-02-07 09:04:35.285 28694-28793/com.example.wasit D/Volley: [1453] BasicNetwork.logSlowRequests: HTTP response for request=&lt;[ ] "#MyAPILink" 0x5557fcc5 NORMAL 1&gt; [lifetime=8506], [size=3841], [rc=200], [retryCount=1]
  </code></pre>