[英]is not public in 'retrofit2.Retrofit' , cannot be accessed from outside
[英]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.