3

description:

I want to get result from direction api using Java Client for Google Maps Services.But when i click onInfoWindoclickthen i got FATAL EXCEPTION: Rate Limited Dispatcher error on my android studio.Please anyone help me.I try solve this issue for 2 days but i don't fix it.

I search google for fix this issue and search stackoverflow but don't find any solution which help me fix my issue.

This is build.gradel:

apply plugin: 'com.android.application'

android {
compileSdkVersion 29
defaultConfig {
    applicationId "com.codingwithmitch.googlemaps2018"
    minSdkVersion 16
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Android Support Design Library
implementation 'com.google.android.material:material:1.0.0'
//RecyclerView
implementation 'androidx.recyclerview:recyclerview:1.0.0'
// Support multidex
implementation 'androidx.multidex:multidex:2.0.1'
// Firebase Core
implementation 'com.google.firebase:firebase-core:17.0.1'
//Firebase Authentication
implementation 'com.google.firebase:firebase-auth:18.1.0'
// Firestore Firestore
implementation 'com.google.firebase:firebase-firestore:20.2.0'

// glide
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

// Circle ImageView
implementation 'de.hdodenhof:circleimageview:2.2.0'

//google location
implementation 'com.google.android.gms:play-services-location:17.0.0'
//Google Play Services for Maps
implementation 'com.google.android.gms:play-services-maps:17.0.0'
//marker clustering
implementation 'com.google.maps.android:android-maps-utils:0.5'
//java library link for google directions:https://github.com/googlemaps/google-maps-services-java
implementation 'com.google.maps:google-maps-services:0.9.4'
implementation 'org.slf4j:slf4j-simple:1.7.25'
}
apply plugin: 'com.google.gms.google-services'

This is my Code:

if(mGeoApiContext == null){
        //GeoApiContext context = new GeoApiContext().setApiKey("YOUR_API_KEY");
        mGeoApiContext = new GeoApiContext.Builder()
                .apiKey(getResources().getString(R.string.google_map_api_key))
                .build();
    }
 @Override
public void onInfoWindowClick(final Marker marker) {
    if (marker.getSnippet().equals("This is you")) {
        marker.hideInfoWindow();
    } else {

        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage(marker.getSnippet())
                .setCancelable(true)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                        calculateDirections(marker);
                        dialog.dismiss();
                    }
                })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                        dialog.cancel();
                    }
                });
        final AlertDialog alert = builder.create();
        alert.show();
    }
}

private void calculateDirections(Marker marker){
    Log.d(TAG, "calculateDirections: calculating directions.");

    com.google.maps.model.LatLng destination = new com.google.maps.model.LatLng(
            marker.getPosition().latitude,
            marker.getPosition().longitude
    );
    DirectionsApiRequest directions = new DirectionsApiRequest(mGeoApiContext);

    directions.alternatives(true);
    directions.origin(
            new com.google.maps.model.LatLng(
                    mUserPosition.getGeoPoint().getLatitude(),
                    mUserPosition.getGeoPoint().getLongitude()
            )
    );
    Log.d(TAG, "calculateDirections: destination: " + destination.toString());
    directions.destination(destination).setCallback(new PendingResult.Callback<DirectionsResult>() {
        @Override
        public void onResult(DirectionsResult result) {
            Log.d(TAG, "calculateDirections: routes: " + result.routes[0].toString());
            Log.d(TAG, "calculateDirections: duration: " + result.routes[0].legs[0].duration);
            Log.d(TAG, "calculateDirections: distance: " + result.routes[0].legs[0].distance);
            Log.d(TAG, "calculateDirections: geocodedWayPoints: " + result.geocodedWaypoints[0].toString());

            Log.d(TAG, "onResult: successfully retrieved directions.");
            //addPolylinesToMap(result);
        }

        @Override
        public void onFailure(Throwable e) {
            Log.e(TAG, "calculateDirections: Failed to get directions: " + e.getMessage() );

        }
    });
}

This is Exception:

E/AndroidRuntime: FATAL EXCEPTION: Rate Limited Dispatcher
Process: com.codingwithmitch.googlemaps2018, PID: 15839
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/ZonedDateTime;
    at com.google.maps.internal.OkHttpPendingResult.parseResponse(OkHttpPendingResult.java:241)
    at com.google.maps.internal.OkHttpPendingResult.onResponse(OkHttpPendingResult.java:207)
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174)
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
    at java.lang.Thread.run(Thread.java:761)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.ZonedDateTime" on path: DexPathList[[zip file "/data/app/com.codingwithmitch.googlemaps2018-1/base.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.codingwithmitch.googlemaps2018-1/lib/arm, /system/lib, /vendor/lib, /system/vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at com.google.maps.internal.OkHttpPendingResult.parseResponse(OkHttpPendingResult.java:241) 
    at com.google.maps.internal.OkHttpPendingResult.onResponse(OkHttpPendingResult.java:207) 
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174) 
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
    at java.lang.Thread.run(Thread.java:761) 
Rabbi hasan
  • 340
  • 1
  • 5
  • 14
  • 1
    `Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.ZonedDateTime" on path: DexPathList` did you google this already? – Zun Aug 07 '19 at 10:44
  • yes.But i don't find proper solution for my project. – Rabbi hasan Aug 07 '19 at 10:48
  • What did the solutions tell you to do? I've had the same problem and I fixed it myself. I'm willing to give you the solution, but it's more important for you to understand how to Google your questions so you no longer have to consult StackOverflow for basic questions – Zun Aug 07 '19 at 10:49
  • Sorry. i try with this Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.ZonedDateTime" on path: DexPathList in google but i don't figure out solution.please help me.and next time i will search properly in google then post question in stackoverflow.Please help me. – Rabbi hasan Aug 07 '19 at 10:59
  • not to sound rude, but I do get search results with the exact same query with solved the issue... – Zun Aug 07 '19 at 11:02
  • please help me.give me solution . – Rabbi hasan Aug 07 '19 at 11:08
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/197605/discussion-between-rabbi-hasan-and-zun). – Rabbi hasan Aug 07 '19 at 11:15

1 Answers1

7

Add the following line to your Project's Gradle File

implementation group: 'com.github.seratch', name: 'java-time-backport', version: '1.0.0'

Make sure you enable Billing on Google Cloud Project

Also Usage of the GoogleMapsServices library on Android should be avoid. Read more about it here https://github.com/googlemaps/google-maps-services-java/blob/master/README.md#intended-usage-of-this-library

BraveEvidence
  • 53
  • 11
  • 45
  • 119