繁体   English   中英

在Retrofit2.retrofit android studio中不公开翻新

[英]retrofit is not public in retrofit2.retrofit android studio

我有这些代码行

公共类RetrofitClient {

private static Retrofit retrofit=null;

public static Retrofit getClient(String baseUrl)
{
    if(retrofit==null)
    {
         retrofit = new Retrofit().Builder()
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

    }

    return retrofit;
}

}

我得到这个错误...

错误:类Retrofit中的构造函数Retrofit无法应用于给定类型; 必需:okhttp3.Call.Factory,HttpUrl,List,List,Executor,boolean找到:无参数原因:实际和正式参数列表的长度不同

如果我将光标放在错误Retrofit上,我可以看到它说

Retrofit(okhttp3 .....)在'retrofit2.retrofit'中不公开。无法从外部包访问

有什么帮助吗?

您应该正确编写如下所述的代码。

public class RetrofitClient {
    private static Retrofit retrofit = null;
    public static Retrofit getClient1(String baseUrl) {
        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(baseUrl)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }
        return retrofit;
    }
}

好吧,我的坏人...我应该使用Retrofit.Builder()而不是Retrofit().Builder()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM