java.io.IOException: grpc 失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45012289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 01:50:15  来源:igfitidea点击:

java.io.IOException: grpc failed

javaandroidgoogle-mapsgoogle-geocoder

提问by Siqve

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

当我使用 call getFromLocationName 时,我得到一个描述为“grpc failed”的 IOException。

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 SDK 版本(API 级别):25

Android Studio plugins are up to date.

Android Studio 插件是最新的。

Thanks in advance!

提前致谢!

EDIT:

编辑:

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

现在问题似乎已解决,这是我的解决方案。

采纳答案by Siqve

UPDATE:

更新:

The problem seems to be solved now. I'm not sure if it the problem ever was on my end, so if you had this problem prior to this post, re-run your app and see if it works now.

现在问题似乎已经解决了。我不确定问题是否出在我的身上,所以如果你在这篇文章之前遇到了这个问题,重新运行你的应用程序,看看它现在是否有效。

If it still doesn't work, here is the stuff I did myself that "might" have made it work:

如果它仍然不起作用,这里是我自己做的“可能”使它起作用的东西:

  1. I uninstalled and deleted all files related to Android Studio. (NOTthe project files).
  2. I then reinstalled Android Studio, and reopened the project back up.
  3. When running the app (I'm using Android Studio's built in emulator) I used a different virtual device and device API. This time I ran it on Pixel, with API 23, x86_64.
  1. 我卸载并删除了与 Android Studio 相关的所有文件。(不是项目文件)。
  2. 然后我重新安装了 Android Studio,并重新打开了该项目。
  3. 运行应用程序时(我使用的是 Android Studio 的内置模拟器),我使用了不同的虚拟设备和设备 API。这次我在 Pixel 上运行它,使用 API 23,x86_64。

回答by Arti patel

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?

可能您仅在 genymotion 和 android studio 模拟器中遇到此问题。我在使用 genymotion 和 android studio 模拟器时遇到了同样的问题,然后我在 android 真实设备中检查了它。它对我很有用。你在真机上检查过吗?

回答by Aamir Rafiq

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.

我在 Android 4.4.2 设备上多次遇到这个问题。对我来说,解决方案只是重新启动手机。没有代码更新没有Android studio卸载。

回答by SagunKho

I finally got this to work by using the following configuration for version 25 SDK, Build Tools and API emulator.

我最终通过对 25 版 SDK、构建工具和 API 模拟器使用以下配置来使其工作。

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.example..."
        minSdkVersion 15
        targetSdkVersion 25

Also using Google API version 11.0.2.

还使用 Google API 版本 11.0.2。

回答by Tobus

Today (2017-09-16) my Android Studio (2.3.3) got an update for Google Play servicesto revision 44. The issue was fixed afterwards. No code or setup changes from my side.

今天 (2017-09-16) 我的 Android Studio (2.3.3) 将Google Play 服务更新到了修订版 44。问题后来得到了解决。我这边没有任何代码或设置更改。

回答by Chulo

In my case I just turned on (permission granted) the Position from app permission setting.

就我而言,我刚刚从应用程序权限设置中打开(授予权限)位置。

回答by Lubos Prague

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.

这也发生在我安装了奥利奥的三星 S7 Edge 手机上。它只发生在我打开飞行模式时(并不总是 - 意味着某些东西可能已被缓存)。我没有探索 Geocoder 的本质,但我认为它需要某种连接来获取信息(这也可以解释为什么在模拟器上经常发生这种情况)。对我来说,解决方案是检查网络连接状态并仅在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
    }
  }
};

回答by Daniele

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

就像谷歌写的,你不应该在 UI 线程上调用这个方法

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

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

我通过在 new 中运行此操作解决了这个问题Thread,然后如果我需要更新一些 UI 视图,我会在runOnUiThread

回答by Nikolay Nikiforchuk

It works for me if introduce Geocoder as singleton for application rather than create it every time. Make sure to call Geocoder.getFromLocationName() from worker thread.

如果将 Geocoder 作为应用程序的单例引入而不是每次都创建它,它对我有用。确保从工作线程调用 Geocoder.getFromLocationName()。

For example:

例如:

class Application {
    private val geoCoder = Geocoder(context, Locale.getDefault())
    ...
}

class SomeClass {

    @WorkerThread
    fun doSmth(){
       application.geoCoder.getFromLocationName("London", 10)
       ...
    }
}

回答by Ali Khazaei

I think this depends on the location of the device. because google map sometimes not working properly in some area. I'm from Iran and I also had this problem on real device and emulator. After a while go with this problem, I used a vpn application and it worked on the real device and emulator. because vpn application changed my ip address.

我认为这取决于设备的位置。因为谷歌地图有时在某些地区无法正常工作。我来自伊朗,我在真实设备和模拟器上也遇到了这个问题。过了一段时间解决了这个问题,我使用了一个 vpn 应用程序,它可以在真实设备和模拟器上运行。因为 vpn 应用程序更改了我的 IP 地址。