英文:
Mapbox Autocomplete Search Crashes The Application When A Letter Is Typed
问题
我按照 Mapbox 的教程 链接在这里,展示了如何在 Android 应用程序中添加自动完成搜索栏。
这是在我的 MainActivity 中的 Java 代码:
private String my_token = "<来自 Mapbox 的令牌>";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new PlaceAutocomplete.IntentBuilder()
.accessToken(my_token)
.build(this);
startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && requestCode == 1) {
CarmenFeature feature = PlaceAutocomplete.getPlace(data);
Toast.makeText(this, feature.text(), Toast.LENGTH_LONG).show();
}
}
一切都能正常渲染,但是当我输入甚至只是一个字母时,应用程序会崩溃,并且我从日志中得到了这个长错误:
2020-09-18 12:30:01.271 21918-21918/com.alpha.istack E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.alpha.istack, PID: 21918
java.lang.BootstrapMethodError: Exception from call site #4 bootstrap method
at okhttp3.internal.Util.<clinit>(Util.java:87)
at okhttp3.internal.Util.skipLeadingAsciiWhitespace(Util.java:321)
at okhttp3.HttpUrl$Builder.parse(HttpUrl.java:1313)
at okhttp3.HttpUrl.get(HttpUrl.java:917)
at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:492)
...
...
...
Caused by: java.lang.ClassCastException: Bootstrap method returned null
at okhttp3.internal.Util.<clinit>(Util.java:87)
...
...
...
这个错误我不太明白。我希望有人能够帮助我。我已经仔细检查了所有的依赖项、清单文件和布局文件,但是没有找到可能导致应用程序崩溃的原因。谢谢。
英文:
I followed a tutorial on Mapbox link here that shows how to add an autocomplete search bar on Android application.
This is the java code in my MainActivity
private String my_token = "<my-token-from-mapbox>";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new PlaceAutocomplete.IntentBuilder()
.accessToken(my_token)
.build(this);
startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && requestCode == 1) {
CarmenFeature feature = PlaceAutocomplete.getPlace(data);
Toast.makeText(this, feature.text(), Toast.LENGTH_LONG).show();
}
}
It all renders fine but when I type even just a single letter, the application crashes and I get this long error from the logcat
2020-09-18 12:30:01.271 21918-21918/com.alpha.istack E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.alpha.istack, PID: 21918
java.lang.BootstrapMethodError: Exception from call site #4 bootstrap method
at okhttp3.internal.Util.<clinit>(Util.java:87)
at okhttp3.internal.Util.skipLeadingAsciiWhitespace(Util.java:321)
at okhttp3.HttpUrl$Builder.parse(HttpUrl.java:1313)
at okhttp3.HttpUrl.get(HttpUrl.java:917)
at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:492)
at com.mapbox.core.MapboxService.getService(MapboxService.java:132)
at com.mapbox.api.geocoding.v5.MapboxGeocoding.initializeCall(MapboxGeocoding.java:86)
at com.mapbox.core.MapboxService.getCall(MapboxService.java:69)
at com.mapbox.core.MapboxService.enqueueCall(MapboxService.java:95)
at com.mapbox.mapboxsdk.plugins.places.autocomplete.viewmodel.PlaceAutocompleteViewModel.onQueryChange(PlaceAutocompleteViewModel.java:87)
at com.mapbox.mapboxsdk.plugins.places.autocomplete.ui.PlaceAutocompleteFragment.onQueryChange(PlaceAutocompleteFragment.java:155)
at com.mapbox.mapboxsdk.plugins.places.autocomplete.ui.SearchView.onTextChanged(SearchView.java:82)
at android.widget.TextView.sendOnTextChanged(TextView.java:9828)
at android.widget.TextView.handleTextChanged(TextView.java:9925)
at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:12750)
at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:1263)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:575)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:506)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:36)
at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:861)
at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:207)
at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:187)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:365)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:94)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7107)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:536)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)
***Caused by: java.lang.ClassCastException: Bootstrap method returned null***
at okhttp3.internal.Util.<clinit>(Util.java:87) 
at okhttp3.internal.Util.skipLeadingAsciiWhitespace(Util.java:321) 
at okhttp3.HttpUrl$Builder.parse(HttpUrl.java:1313) 
at okhttp3.HttpUrl.get(HttpUrl.java:917) 
at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:492) 
at com.mapbox.core.MapboxService.getService(MapboxService.java:132) 
at com.mapbox.api.geocoding.v5.MapboxGeocoding.initializeCall(MapboxGeocoding.java:86) 
at com.mapbox.core.MapboxService.getCall(MapboxService.java:69) 
at com.mapbox.core.MapboxService.enqueueCall(MapboxService.java:95) 
at com.mapbox.mapboxsdk.plugins.places.autocomplete.viewmodel.PlaceAutocompleteViewModel.onQueryChange(PlaceAutocompleteViewModel.java:87) 
at com.mapbox.mapboxsdk.plugins.places.autocomplete.ui.PlaceAutocompleteFragment.onQueryChange(PlaceAutocompleteFragment.java:155) 
at com.mapbox.mapboxsdk.plugins.places.autocomplete.ui.SearchView.onTextChanged(SearchView.java:82) 
at android.widget.TextView.sendOnTextChanged(TextView.java:9828) 
at android.widget.TextView.handleTextChanged(TextView.java:9925) 
at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:12750) 
at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:1263) 
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:575) 
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:506) 
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:36) 
at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:861) 
at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:207) 
at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:187) 
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:365) 
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:94) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:224) 
at android.app.ActivityThread.main(ActivityThread.java:7107) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:536) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876) 
which I don't clearly understand. I hope someone out there can help me.
I've double checked all the dependencies, manifest file and layout files but wasn't able to find anything that might have caused the app to crash.
Thanks.
答案1
得分: 3
请查看 https://stackoverflow.com/a/60991383/6358488
尝试将以下代码块添加到您的应用级别 build.gradle
文件的 android { }
部分中:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
如果您使用的是 Kotlin,还应添加以下代码块:
kotlinOptions {
jvmTarget = "1.8"
}
https://developer.android.com/studio/write/java8-support#supported_features
英文:
See https://stackoverflow.com/a/60991383/6358488
Try adding the following block inside of the android { }
section in your app-level build.gradle
file:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
If you're using Kotlin, you should add the following block as well:
kotlinOptions {
jvmTarget = "1.8"
}
https://developer.android.com/studio/write/java8-support#supported_features
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论