I want to get data from the request via the retrofit library. In the onRespone () method, for all tutorials, the List and Response parameters, and I have Call> and I cannot now transfer it to a regular sheet to fill in the data. Here is my fragment code:

public class FeaturedFragment extends Fragment { public static final String ROOT_URL = "https://api.vid.me"; private List <Video> videos; RecyclerView recList; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_featured, container, false); recList = (RecyclerView) rootView.findViewById(R.id.cardList); recList.setHasFixedSize(true); LinearLayoutManager llm = new LinearLayoutManager(getActivity()); llm.setOrientation(LinearLayoutManager.VERTICAL); recList.setLayoutManager(llm); return rootView; } public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); try { getVideos(); } catch (IOException e) { e.printStackTrace(); } } private void getVideos() throws IOException { Retrofit retrofitAdapter = new Retrofit.Builder() .baseUrl(ROOT_URL) .build(); VideoApi videoApi = retrofitAdapter.create(VideoApi.class); videoApi.getFeaturedVideo(new Callback<List<Video>>() { @Override public void onResponse(Call<List<Video>> call, Response<List<Video>> response) { videos = call;//ОШИБКА ЗДЕСЬ!Нужен java.util.List найден retrofit2.Call } @Override public void onFailure(Call<List<Video>> call, Throwable t) { } }); } } 

videoApi class:

 public interface VideoApi { @GET("/videos/fatured") Call<Video> getFeaturedVideo(Callback<List<Video>> response); } 

Video class:

  public class Video { private String url,title,description; private int score; public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public int getScore() { return score; } public void setScore(int score) { this.score = score; } } 
  • You have an error due to the fact that you are trying to build List <Video> to Call <List <Video >> - Android Android

1 answer 1

It is necessary to take away from here response.body();

  @Override public void onResponse(Call<List<Video>> call, Response<List<Video>> response) { videos = response.body(); } 

response.body() - returns your serialized object

  • can you please in more detail? - Rostislav Prozorovsky
  • Updated the answer, look - Chaynik
  • thanks, earned - Rostislav Prozorovsky