几天前将我的Android Studio更新到最新版本后,我在翻新和okhttp上遇到问题。在此之前,我的代码可以正常工作。这是改装客户端的类,它崩溃了
public class ApiClient {
public static final String BASE_URL = "myapiurl";
private static Retrofit mRetrofit = null;
public static Retrofit getClient() {
if (mRetrofit ==null) {
Gson gson = new GsonBuilder()
.setLenient()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss")
.create();
mRetrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
return mRetrofit;
}
}
我得到的错误非常普遍,我不知所措。
2019-03-03 07:15:15.774 21769-21769/com.instreamwater.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.instreamwater.app, PID: 21769
java.lang.BootstrapMethodError: Exception from call site #0 bootstrap method
at okhttp3.internal.Util.<clinit>(Unknown Source:111)
at okhttp3.internal.Util.skipLeadingAsciiWhitespace(Unknown Source:0)
at okhttp3.HttpUrl$Builder.parse(Unknown Source:11)
at okhttp3.HttpUrl.get(Unknown Source:6)
at retrofit2.Retrofit$Builder.baseUrl(Unknown Source:5)
at com.instreamwater.app.network.ApiClient.getClient(Unknown Source:12)
at com.instreamwater.app.activity.LogInOrSignUpActivity.a(Unknown Source:30)
at com.instreamwater.app.activity.LogInOrSignUpActivity.a(Unknown Source:0)
at com.instreamwater.app.activity.LogInOrSignUpActivity$4.onClick(Unknown Source:32)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassCastException: Bootstrap method returned null
at okhttp3.internal.Util.<clinit>(Unknown Source:111)
at okhttp3.internal.Util.skipLeadingAsciiWhitespace(Unknown Source:0)
at okhttp3.HttpUrl$Builder.parse(Unknown Source:11)
at okhttp3.HttpUrl.get(Unknown Source:6)
at retrofit2.Retrofit$Builder.baseUrl(Unknown Source:5)
at com.instreamwater.app.network.ApiClient.getClient(Unknown Source:12)
at com.instreamwater.app.activity.LogInOrSignUpActivity.a(Unknown Source:30)
at com.instreamwater.app.activity.LogInOrSignUpActivity.a(Unknown Source:0)
at com.instreamwater.app.activity.LogInOrSignUpActivity$4.onClick(Unknown Source:32)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2019-03-03 07:15:15.945 7099-7166/system_process E/InputDispatcher: channel 'b2904e com.instreamwater.app/com.instreamwater.app.activity.LogInOrSignUpActivity (server)'
〜频道无法恢复,将被处置!
最近有人在Android Studio更新后甚至在过去曾遇到此问题,并且对如何解决此问题有任何建议吗?我正在使用implementation 'com.squareup.retrofit2:retrofit:2.5.0'
中的最新版本,例如:build.gradle
。
答案 0 :(得分:1)
万一这对任何人都有帮助,我将其发布到Github项目并收到答案here,以解决我的问题。
答案 1 :(得分:0)
我添加:
android {
compileOptions {
targetCompatibility = "8"
sourceCompatibility = "8"
}
}
但是它不起作用,所以我将我的项目迁移到AdroidX,并且确实可行。