Unable to use retrofit2 convertor

Viewed 72

So I'm trying to use retrofit GsonConvertorFactory but in the android studio, it is not reading because of which I'm unable to run.

    public class start {

            private  static final String id = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
            private  static final String url = "https://XXX/YY/ZZ";

            public static PostService postService = null;
            public static PostService getService()

            {
                if (postService == null) {
                    Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConvertorFactory.create()).build();
                    postService = retrofit.create((PostService.class));
                }
                return postService;
            }


        public interface PostService{
            @GET("?=id"+id )
            Call<PostDia> getPostDia();
        }
    }
2 Answers

You need to add:

    implementation 'com.squareup.retrofit2:converter-gson:2.8.1'

to the build.gradle file

I figured out that GsonConvertorFactory is only supported by 2.3.0 version and not any other version so try changing your dependencies

implementation 'com.squareup.retrofit2:converter-gson:2.3.0' implementation 'com.squareup.retrofit2:retrofit:2.3.0'

Related