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?
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);your okHttpClient! Well, add the dependencycompile 'com.squareup.okhttp3:logging-interceptor:3.4.1'and watch the log - katso