2

这是我的应用程序类,然后是 okhttp 初始化。除了网络调用,我能调试的所有东西

public class App extends BaseApp {


    @Override
    public void onCreate() {
        ActivityLifecycleCallback.register(this);

            Stetho.initialize(
                    Stetho.newInitializerBuilder(this)
                            .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
                            .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
                            .build());
        }

}

这是 OkHttpClass

private static OkHttpClient okHttpClient = new OkHttpClient();

private static OkHttpClient getOkHttpClient() {
    if (okHttpClient == null) {
        okHttpClient = new OkHttpClient();
            okHttpClient.networkInterceptors().add(new StethoInterceptor());
    }
    return okHttpClient;
}
4

1 回答 1

1

正如@guilaume_fr 提到的,

okHttpClient永远不会为空,因为您已经对其进行了初始化。尝试删除声明,只需写private static OkHttpClient okHttpClient;

请接受并关闭此问题。

于 2016-03-23T06:36:42.080 回答