简体   繁体   English

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

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

I'm having these lines of code 我有这些代码行

public class RetrofitClient { 公共类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; 错误:类Retrofit中的构造函数Retrofit无法应用于给定类型; required: okhttp3.Call.Factory,HttpUrl,List,List,Executor,boolean found: no arguments reason: actual and formal argument lists differ in length 必需:okhttp3.Call.Factory,HttpUrl,List,List,Executor,boolean找到:无参数原因:实际和正式参数列表的长度不同

If i put my cursor on the error Retrofit i can see that it says 如果我将光标放在错误Retrofit上,我可以看到它说

Retrofit(okhttp3.....)is not public in 'retrofit2.retrofit'.Cannot be accessed from outside package Retrofit(okhttp3 .....)在'retrofit2.retrofit'中不公开。无法从外部包访问

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()

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

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