Mapbox自动完成搜索在输入字母时导致应用程序崩溃。

huangapple go评论88阅读模式
英文:

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 = &quot;&lt;my-token-from-mapbox&gt;&quot;;
@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 &amp;&amp; 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.&lt;clinit&gt;(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.&lt;clinit&gt;(Util.java:87)&#160;
    at okhttp3.internal.Util.skipLeadingAsciiWhitespace(Util.java:321)&#160;
    at okhttp3.HttpUrl$Builder.parse(HttpUrl.java:1313)&#160;
    at okhttp3.HttpUrl.get(HttpUrl.java:917)&#160;
    at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:492)&#160;
    at com.mapbox.core.MapboxService.getService(MapboxService.java:132)&#160;
    at com.mapbox.api.geocoding.v5.MapboxGeocoding.initializeCall(MapboxGeocoding.java:86)&#160;
    at com.mapbox.core.MapboxService.getCall(MapboxService.java:69)&#160;
    at com.mapbox.core.MapboxService.enqueueCall(MapboxService.java:95)&#160;
    at com.mapbox.mapboxsdk.plugins.places.autocomplete.viewmodel.PlaceAutocompleteViewModel.onQueryChange(PlaceAutocompleteViewModel.java:87)&#160;
    at com.mapbox.mapboxsdk.plugins.places.autocomplete.ui.PlaceAutocompleteFragment.onQueryChange(PlaceAutocompleteFragment.java:155)&#160;
    at com.mapbox.mapboxsdk.plugins.places.autocomplete.ui.SearchView.onTextChanged(SearchView.java:82)&#160;
    at android.widget.TextView.sendOnTextChanged(TextView.java:9828)&#160;
    at android.widget.TextView.handleTextChanged(TextView.java:9925)&#160;
    at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:12750)&#160;
    at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:1263)&#160;
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:575)&#160;
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:506)&#160;
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:36)&#160;
    at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:861)&#160;
    at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:207)&#160;
    at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:187)&#160;
    at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:365)&#160;
    at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:94)&#160;
    at android.os.Handler.dispatchMessage(Handler.java:106)&#160;
    at android.os.Looper.loop(Looper.java:224)&#160;
    at android.app.ActivityThread.main(ActivityThread.java:7107)&#160;
    at java.lang.reflect.Method.invoke(Native Method)&#160;
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:536)&#160;
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)&#160;

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 = &quot;1.8&quot;
}

https://developer.android.com/studio/write/java8-support#supported_features

huangapple
  • 本文由 发表于 2020年9月18日 12:47:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63949483.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定