I'm having these lines of code
public class 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;
}
}
and i'm getting this error...
error: constructor Retrofit in class Retrofit cannot be applied to given types; required: okhttp3.Call.Factory,HttpUrl,List,List,Executor,boolean found: no arguments reason: actual and formal argument lists differ in length
If i put my cursor on the error Retrofit i can see that it says
Retrofit(okhttp3.....)is not public in 'retrofit2.retrofit'.Cannot be accessed from outside package
Any help please?
You should be correct you code as below mentioned.
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()
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.