android – Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $ ….z-ThrowExceptions

Exception or error:

Why i am getting this error?

“Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $”

io.reactivex.exceptions.OnErrorNotImplementedException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $

public class RetrofitClient {
    private static Retrofit retrofit=null;
    private static Gson gson = new GsonBuilder()
            .setLenient()
            .create();
    public static Retrofit getClient(String baseUrl){
        if(retrofit == null){
            retrofit = new Retrofit.Builder()
                    .baseUrl(baseUrl)
                    .addConverterFactory(GsonConverterFactory.create(gson))
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .build();
        }
        return retrofit;
    }

public interface API {
@GET("getmenu.php")
Observable<List <MainMenu>> getMenu();
}

MainMenu.class :

public class MainMenu {
    public String ID;
    public String Name;
    public String Link;

}

enter image description here

How to solve:

You are getting the error because what comes in json is not compliant with List <MainMenu> model. If you want to have specific answer, post your json and the MainMenu model.

Leave a Reply

Your email address will not be published. Required fields are marked *