【问题标题】:OkHttpClient ExceptionInInitializerErrorOkHttpClient ExceptionInInitializerError
【发布时间】:2020-07-08 07:52:03
【问题描述】:

第一次使用 httpOk 和改造。 我正在使用另一名员工的代码,但无法使其工作,即使在上网查看潜在错误后也是如此。

public static Retrofit getBsfBuilder() {
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

    retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .client(client)
            .build();

     return retrofit;
}

使用上面的 BASE_URL 声明,并改型为 null。

错误是

E/AndroidRuntime: 致命异常: main 进程:,PID:5305 java.lang.ExceptionInInitializerError

【问题讨论】:

    标签: android-studio retrofit2 okhttp


    【解决方案1】:

    问题是因为我使用的是版本 19 的 android,带有最新版本的 okhttp,查看How to fix Expected Android API level 21+ but was 19 in Android 了解更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-05
      • 2014-03-04
      • 1970-01-01
      相关资源
      最近更新 更多