Get himself:

public interface GetDescriptionForecastApi { @GET("feed_android.php") Call<GetDescriptionForecastModel> getList (@Query("action=get_description&id=") int id);} 

But in the adapter to the RecylcerView I call this request when I click on CardView:

  @Override public void onBindViewHolder(final ForecastViewHolder holder, final int position) { final DataForecast.DataBean searchModel = list.get(position); holder.timedate.setText(searchModel.getDate()); holder.game.setText(searchModel.getCommand()); holder.forecast.setText("Фора1 по очкам (-4.5) @ " + searchModel.getKf()); holder.cv_forecast.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (holder.about.getVisibility() == View.GONE) { GetDescriptionForecastApi service = GetDescriptionForecastService.getInstance(holder.cv_forecast.getContext()).getApi(); Call<GetDescriptionForecastModel> descriptionCall = service.getList(searchModel.getId()); descriptionCall.enqueue(new Callback<GetDescriptionForecastModel>() { @Override public void onResponse(Call<GetDescriptionForecastModel> call, Response<GetDescriptionForecastModel> response) { GetDescriptionForecastModel dataDescription = response.body(); result = dataDescription.getData(); holder.about.setText(result); holder.about.setVisibility(View.VISIBLE); holder.cv_forecast.setBackgroundResource(R.color.forecast_about_all); } @Override public void onFailure(Call<GetDescriptionForecastModel> call, Throwable t) { Log.e("Tag", t.getMessage()); // здесь всегда оказываюсь } }); } else { holder.about.setVisibility(View.GONE); holder.cv_forecast.setBackgroundResource(R.color.white); } } }); } 

Well, here is the service itself that builds retrofit:

 public class GetDescriptionForecastService { private static GetDescriptionForecastService instance; public static GetDescriptionForecastService getInstance(Context context) { if (instance == null) { instance = new GetDescriptionForecastService(context); } return instance; } private static final String BASE_URL = "http://******.ru/***/"; private GetDescriptionForecastApi api; private GetDescriptionForecastService(Context context) { OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor( new Interceptor() { @Override public okhttp3.Response intercept(Chain chain) throws IOException { Request request = chain.request().newBuilder() .addHeader("Accept", "Application/JSON").build(); return chain.proceed(request); } }).build(); Retrofit retrofitRef = new Retrofit.Builder() .baseUrl(BASE_URL) .client(okHttpClient) .addConverterFactory(GsonConverterFactory.create()) .build(); api = retrofitRef.create(GetDescriptionForecastApi.class); } public GetDescriptionForecastApi getApi() { return api; }} 

It turns out such Exception in the CardView adapter:

E / Tag: End of input at line 1 column 1 path $

What could be the error?

  • And what is the question then? - katso
  • why exeption - Taras Zhupnik
  • It seems that JSON is not valid, log the answer, see what the server sends. - katso
  • Hint how to secure, otherwise I don’t understand where exactly - Taras Zhupnik
  • one
    Add interceptor HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); your okHttpClient! Well, add the dependency compile 'com.squareup.okhttp3:logging-interceptor:3.4.1' and watch the log - katso

1 answer 1

You have a strange interface with parameters. It is necessary to separate the parameters. Something like this:

 public interface GetDescriptionForecastApi { @GET("feed_android.php") Call<GetDescriptionForecastModel> getList (@Query("action") String action, @Query("id") int id);} 

Call this:

 Call<GetDescriptionForecastModel> descriptionCall = service.getList("get_description", searchModel.getId()); 
  • You are always on top !! Thank you very much! You have no assumptions why it also works on every 14 elements of RecyclerView? And why with notifyDataSetChanged () does not update? - Taras Zhupnik
  • one
    I don’t know about the triggering, and notifyDataSetChanged doesn’t work, apparently because you are assigning new data to the markup elements, and not updating the data in the adapter's data list. If the result of the query is placed in the list of models and cause an update, then it should work - Yuriyi