为什么PlaceAutocompleteFragment与NoSuchMethodError崩溃?

时间:2017-11-14 10:20:27

标签: android google-maps google-places-api google-places googleplacesautocomplete

我正试图在我的android中找到谷歌地图的地方 我的代码是

PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            // TODO: Get info about the selected place.
            Log.i(TAG, "Place: " + place.getName());

            String placeDetailsStr = place.getName() + "\n"
                    + place.getId() + "\n"
                    + place.getLatLng().toString() + "\n"
                    + place.getAddress() + "\n"
                    + place.getAttributions();
        }

        @Override
        public void onError(Status status) {
            // TODO: Handle the error.
            Log.i(TAG, "An error occurred: " + status);
        }
    });

但是当我尝试输入某些内容时,它会因错误而崩溃

FATAL EXCEPTION: main                                                    Process: com.example.asset.lab13_bonus, PID: 1192
                                                                         java.lang.NoSuchMethodError: No virtual method zzbo(Landroid/content/Context;)V in class Lcom/google/android/gms/common/GoogleApiAvailability; or its super classes (declaration of 'com.google.android.gms.common.GoogleApiAvailability' appears in /data/app/com.example.asset.lab13_bonus-bAk1S6P8t8HToIo1FR8JeA==/split_lib_dependencies_apk.apk:classes12.dex)
                                                                             at com.google.android.gms.location.places.ui.zza$zza.build(Unknown Source:79)
                                                                             at com.google.android.gms.location.places.ui.PlaceAutocomplete$IntentBuilder.build(Unknown Source:0)
                                                                             at com.google.android.gms.location.places.ui.PlaceAutocompleteFragment.zzboi(Unknown Source:42)
                                                                             at com.google.android.gms.location.places.ui.PlaceAutocompleteFragment.zza(Unknown Source:0)
                                                                             at com.google.android.gms.location.places.ui.PlaceAutocompleteFragment$1.onClick(Unknown Source:2)
                                                                             at android.view.View.performClick(View.java:6256)
                                                                             at android.view.View$PerformClick.run(View.java:24697)
                                                                             at android.os.Handler.handleCallback(Handler.java:789)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                             at android.os.Looper.loop(Looper.java:164)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                             at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Gradle依赖项:

compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.android.gms:play-services-places:9.4.0'
compile "com.google.android.gms:play-services-base:9.4.0"
这是什么意思? 有人能帮我吗? 可能是因为设备无法正常工作?

2 个答案:

答案 0 :(得分:3)

试试这个,

compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.google.android.gms:play-services-places:9.4.0'
compile "com.google.android.gms:play-services-base:9.4.0"

答案 1 :(得分:1)

尝试确保所有依赖项都是相同版本以避免冲突,无论是9.4.0还是11.0.4。较旧的版本可以正常工作,但您可能会错过新版本提供的某些功能。