title: Android Retrofit: Display in Recyclerview
body: <p>I have a problem on how to display my json data to a recycler view. Here is my JSON data in which I want to display the "errors" in the recycler view. I tried some ways but it always forces close. </p>
  
  <pre><code>{
   "result": true,
   "errors": [
     {
      "id": "e1812696024",
      "offset": 2,
      "length": 2,
      "bad": "is",
      "better": [
        "am"
          ],
      "type": "grammar"
     },
     {
      "id": "e962925648",
      "offset": 8,
      "length": 8,
      "bad": "engeneer",
      "better": [
         "engineer",
         "engender"
          ],
      "type": "spelling"
      }
   ]
  }
  </code></pre>
  
  <p>Here are my codes:
  Service.class (Interface)</p>
  
  <pre><code>public interface Service {
  
        @POST("/check.php")
        Call&lt;InputResult&gt; readErrors(@Query("userInput") String userInput,
                                     @Query("apiKey") String apiKey);
   }
  </code></pre>
  
  <p>Model classes:
  InputResult.java</p>
  
  <pre><code>public class InputResult {
  
      @SerializedName("result")
      private String result;
  
      @SerializedName("errors")
      private List&lt;Errors&gt; errors;
  
     //getter and setter
  }
  </code></pre>
  
  <p>Errors.java</p>
  
  <pre><code>public class Errors {
  
     @SerializedName("id")
     private String id;
  
     @SerializedName("offset")
     private int offset;
  
     @SerializedName("length")
     private int length;
  
     @SerializedName("bad")
     private String bad;
  
     //getter and setter
  }
  </code></pre>
  
  <p>Adapter</p>
  
  <pre><code>public class ResultAdapter extends RecyclerView.Adapter&lt;ResultAdapter.ResultViewHolder&gt;{
  
  Context mContext;
  List&lt;Photo&gt; photoList = new ArrayList&lt;&gt;();
  List&lt;Errors&gt; errorsList = new ArrayList&lt;&gt;();
  
  public ResultAdapter (Context mContext, List&lt;Errors&gt; errorsList){
      this.errorsList = errorsList;
      this.mContext = mContext;
  }
  
  @Override
  public ResultViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
      View view = LayoutInflater.from(viewGroup.getContext())
              .inflate(R.layout.result_card, viewGroup, false);
      return new ResultViewHolder(view);
  }
  
  @Override
  public void onBindViewHolder(ResultViewHolder resultViewHolder, int i) {
  
      Errors errors = errorsList.get(i);
      resultViewHolder.mNumErrorsTextView.setText(errorsList.size());
      resultViewHolder.mIdErrorTextView.setText(errors.getId());
      resultViewHolder.mLengthErrorTextView.setText(errors.getLength());
      resultViewHolder.mBadErrorTextView.setText(errors.getBad());
  }
  
  @Override
  public int getItemCount() {
      return errorsList.size();
  }
  
   //Viewholder
   ...
   }
  </code></pre>
  
  <p>Fragment class:</p>
  
  <pre><code>ublic class Tab1Fragment_GrammarChecker extends Fragment {
  
  private static final String TAG = "Tab1Fragment";
  private PhotoAdapter adapter;
  
  @BindView(R.id.InputTextEditText)
  EditText mInputGrammarEditText;
  
  @BindView(R.id.ErrorsRecyclerView)
  RecyclerView mErrorsRecyclerView;
  
  List&lt;Errors&gt; errors = new ArrayList&lt;&gt;();
  public ArrayList&lt;Errors&gt; errorArrayList = new ArrayList&lt;&gt;();
  
  List&lt;InputResult&gt; inputResults = new ArrayList&lt;&gt;();
  public ArrayList&lt;InputResult&gt; inputResultArrayList = new ArrayList&lt;&gt;();
  
  public static String userInput = "I is an engeneer!";
  public String apiKey = ""; 
  
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.tab1_grammar_checker, container, false);
      ButterKnife.bind(this, view);
      RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
      mErrorsRecyclerView.setLayoutManager(layoutManager);
      loadJson();
  
      return view;
  }
  
  public void loadJson(){
  
      Retrofit.Builder builder = new Retrofit.Builder()
              .baseUrl("https://api.textgears.com")
              .addConverterFactory(GsonConverterFactory.create());
  
      Retrofit retrofit = builder.build();
  
      Service serviceAPI = retrofit.create(Service.class);
      Call&lt;InputResult&gt; loadErrorsCall = serviceAPI.readErrors(userInput, apiKey);
      loadErrorsCall.enqueue(new Callback&lt;InputResult&gt;() {
          @Override
          public void onResponse(Call&lt;InputResult&gt; call, Response&lt;InputResult&gt; response) {
              if (response.isSuccessful()){
                  inputResults = response.body();
                  Log.i("ORIG. ARRAY SIZE", String.valueOf(inputResultArrayList.size()));
                  if (inputResultArrayList != null){
                      for (int i = 0; i &lt; 5; i++){
                          inputResultArrayList.add(inputResults.get(i));
                      }
  
                      Log.i("NEW ARRAY SIZE", String.valueOf(errorArrayList.size()));
                  }
                  mErrorsRecyclerView.setItemAnimator(new DefaultItemAnimator());
                  mErrorsRecyclerView.setAdapter(new ResultAdapter1(getContext(), inputResultArrayList));
                  Log.e("Fragment", response.body().toString());
                  Log.e("Fragment", "SUCCESS");
              }
              else {
                  Log.i("ERROR", "");
              }
  
          }
  
          @Override
          public void onFailure(Call&lt;InputResult&gt; call, Throwable t) {
              Log.i("Error: ", t.getMessage());
          }
      });
  }
  
  }
  </code></pre>
  
  <p>Logcat:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
  Process: renelyn.austria.grammatika, PID: 32547
  java.lang.ClassCastException: renelyn.austria.grammatika.Model.InputResult cannot be cast to java.util.List
      at renelyn.austria.grammatika.Tab1Fragment_GrammarChecker$1.onResponse(Tab1Fragment_GrammarChecker.java:95)
      at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:71)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:145)
      at android.app.ActivityThread.main(ActivityThread.java:5832)
      at java.lang.reflect.Method.invoke(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:372)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
  </code></pre>