How to fix: “ grpc failed” while using Geocoder.getFromLocation

Have you ever seen a crash or error logs like below, when accessing location data in Android.

I Geocoder: Geocoder getFromLocation --- mService = android.location.ILocationManager$Stub$Proxy@4f84fe, ex = grpc failed, return results = []
D AndroidRuntime: Shutting down VM
E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: com.your.packagename, PID: 19452
E AndroidRuntime: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
E AndroidRuntime:        at$
E AndroidRuntime:        at
E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
E AndroidRuntime:        at$
E AndroidRuntime:        ... 1 more
E AndroidRuntime: Caused by: grpc failed
E AndroidRuntime:        at android.location.Geocoder.getFromLocation(

The code used for reverse geodecoding is normally look like as below,

        .addOnSuccessListener { location : Location? ->
            // Got last known location. In some rare situations this can be null.
		mLocation = location
                if (mLocation != null) {

    fun getCompleteReadableAddress() {
        val geocoder = Geocoder(this, Locale.getDefault())
        // Address found using the Geocoder.
        var addresses: List<Address> = emptyList()
        if (mLocation != null) {
            Log.d(TAG,"Last known Latitude :: " + mLocation!!.getLatitude() + " Longitude :: " + mLocation!!.getLongitude()
            addresses = geocoder.getFromLocation(
                // In this sample, we get just a single address.
            if (!addresses.isEmpty()) {
                val address = addresses[0]
                Log.d(TAG, "CompleteReadableAddress: " + address)
                Log.d(TAG, "Admin area " + address.adminArea)

The crash has happened while execution of function “geocoder.getFromLocation” which actually does the reverse geodecoding.

Related :   How to center views in LinearLayout and RelativeLayout ?

The possible cause of the failure of this function, might be unstable network connectivity which causes the reverse geodecoding failing. As reported in [1] and [2]


  1. Make sure to check you are connected to network using network check API’s of Android
  2. Add “try catch” around “geocoder.getFromLocation” and display error message from “catch” block saying, address decoding failed retry etc.
  3. Use some default values if you are taking some actions based on users fetched address.

References –


Subscribe with Valid Email Id to receive updates in Inbox. ( Secured by Google FeedBurner )


Leave a Comment

Android Android Applications Android Build system Android Commands Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development & Build Development, Debugging and Performance Tools Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web design and development Website Hosting Wordpress Yocto / Bitbake / Openembedded