Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.io.IOException: grpc failed

When I use call getFromLocationName I get an IOException with description "grpc failed".

Code that's ran

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    try {
        Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
        List<Address> listAdresses = geocoder.getFromLocationName("London", 10);
        Log.i("PlaceInfo", listAdresses.get(0).toString());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Error the console outputs:

07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err: java.io.IOException: grpc failed
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err:     at android.location.Geocoder.getFromLocationName(Geocoder.java:178)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err:     at co.siqve.maplocationdemo.MapsActivity.onMapReady(MapsActivity.java:70)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err:     at com.google.android.gms.maps.zzaj.zza(Unknown Source)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err:     at com.google.android.gms.maps.internal.zzaq.onTransact(Unknown Source)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err:     at android.os.Binder.transact(Binder.java:499)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err:     at com.google.android.gms.maps.internal.aq.a(:com.google.android.gms.DynamiteModulesB:5)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err:     at com.google.maps.api.android.lib6.impl.bb.run(:com.google.android.gms.DynamiteModulesB:5)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err:     at android.os.Handler.handleCallback(Handler.java:751)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err:     at android.os.Looper.loop(Looper.java:154)
07-10 12:01:38.781 13712-13712/co.siqve.maplocationdemo W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6119)
07-10 12:01:38.782 13712-13712/co.siqve.maplocationdemo W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
07-10 12:01:38.782 13712-13712/co.siqve.maplocationdemo W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
07-10 12:01:38.782 13712-13712/co.siqve.maplocationdemo W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Android SDK Version (API Level): 25

Android Studio plugins are up to date.

Thanks in advance!

EDIT:

Problem seems to be fixed now, here is my solution.

like image 757
Siqve Avatar asked Jul 10 '17 12:07

Siqve


6 Answers

I can reproduce this issue (java.io.IOException: grpc failed), when there is no Internet connection on my real device.

like image 54
vvkatwss vvkatwss Avatar answered Nov 18 '22 14:11

vvkatwss vvkatwss


Like Google writes, You should not call this method on UI thread

https://developer.android.com/training/location/display-address#java

I fixed this issue by running this operation in a new Thread, and then if I need to update some UI view I'll do it on runOnUiThread

like image 41
Daniele Avatar answered Nov 18 '22 12:11

Daniele


This issue appeared for me (even though I make the request on a background thread), but in the Android Studio emulator only. A strange workaround that fixes it for me is to turn on and then turn off airplane mode!

like image 18
xjcl Avatar answered Nov 18 '22 14:11

xjcl


May be you are having this issue in genymotion and android studio emulator only. I faced same issue with genymotion and android studio emulator and then i checked it in android real device. It's working good for me. Did you check it in real device?

like image 17
Arti Patel Avatar answered Nov 18 '22 14:11

Arti Patel


I face this issue on Android 4.4.2 device several times. For me the solution is simply to restart the handset. No code update no Android studio uninstall.

like image 14
Aamir Rafiq Avatar answered Nov 18 '22 13:11

Aamir Rafiq


This was happening also on my Samsung S7 Edge phone with Oreo installed. It only happened when I had an airplane mode on (not always - means something might have been cached at some points). I didn't explore the guts of Geocoder but I assume it requires some sort connectivity to get the information (that would also explain why this is happening so often on emulators). For me the solution was to check the network connectivity status and call this only when status != NETWORK_STATUS_NOT_CONNECTED.

For this you can implement a broadcast receiver, that will listen to any status changes on network.

Register receiver

IntentFilter networkFilter = new IntentFilter();
networkFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
getActivity().registerReceiver(NetworkChangeReceiver, networkFilter);

Setup broadcast receiver to handle the broadcast

private BroadcastReceiver NetworkChangeReceiver = new BroadcastReceiver() {

  @Override
  public void onReceive(final Context context, final Intent intent) {
    int status = NetworkUtil.getConnectivityStatusString(context);

    if (status == NetworkUtil.NETWORK_STATUS_NOT_CONNECTED) {
    } else {
      // do your stuff with geocoder here
    }
  }
};
like image 6
Lubos Prague Avatar answered Nov 18 '22 13:11

Lubos Prague