Salman500 Salman500 -3 years ago 214
Android Question

Retrofit Response Failed

I am trying to understand how retrofit works but every time my response is failed I even used GitHub API but still my response failed, am I doing something wrong
I am so confused


Interface Class

Call<List<Weather>> getWeatherData(@Query("q") String cityName,@Query("appid") String apikey);


private final String BASE_URL = "";

Retrofit retrofit = new Retrofit.Builder()

RestApi api = retrofit.create(RestApi.class);

final Call<List<Weather>> weather = api.getWeatherData("rawalpindi",API_KEY);

final ProgressDialog pg = new ProgressDialog(this);
pg.setMessage("Please Wait .....");;

weather.enqueue(new Callback<List<Weather>>() {
public void onResponse(Call<List<Weather>> call, Response<List<Weather>> response) {


Log.d(TAG, "onResponse: "+response.isSuccessful());

Log.d(TAG, "onResponse: "+response.body().get(0).getClouds());


public void onFailure(Call<List<Weather>> call, Throwable t) {

Log.d(TAG, "onFailure: Failed :(");
Log.d(TAG, "onResponseFailed: "+call.request().url());


D/MainActivity: onFailure: Failed :(
D/MainActivity: onResponseFailed:

throwable message

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

Answer Source

Your answer is not a list, is just an object. Use an interceptor to see responses.

As an example, from Call<List<Weather>> you should use just Call<Weather>.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download