小编Sta*_*wer的帖子

Retrofit 2示例教程但GsonConverterFactory显示错误"无法解析符号"

我正在尝试遵循Retrofit的2 教程,但是在这部分代码中有一个GsonConverterFactory显示错误Cannot resolve symbol:

public class ServiceGenerator {

    public static final String API_BASE_URL = "http://your.api-base.url";

    private static OkHttpClient httpClient = new OkHttpClient();
    private static Retrofit.Builder builder =
            new Retrofit.Builder()
                    .baseUrl(API_BASE_URL)
                    //THIS IS THE LINE WITH ERROR!!!!!!!!!!!!
                    .addConverterFactory(GsonConverterFactory.create());

    public static <S> S createService(Class<S> serviceClass) {
        Retrofit retrofit = builder.client(httpClient).build();
        return retrofit.create(serviceClass);
    }
}
Run Code Online (Sandbox Code Playgroud)

之前我在gradle.build中添加了,我不确定是否应该添加GSON,因为他们说Retrofit 1.9有它但是没有提到Retrofit 2:

dependencies {  
    // Retrofit & OkHttp
    compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
}
Run Code Online (Sandbox Code Playgroud)

android gson android-library retrofit okhttp

31
推荐指数
3
解决办法
3万
查看次数

标签 统计

android ×1

android-library ×1

gson ×1

okhttp ×1

retrofit ×1