Kotlin Type inference failed: Not enough information to infer parameter T in fun

/home/espl/Android-Studio-Projects/NIVEDH/app/src/main/java/com/example/espl/nivedh/MainActivity.kt: (214, 35): Type inference failed: Not enough information to infer parameter T in fun <T : Parcelable!> getParcelableExtra(p0: String!): T!
Please specify it explicitly.


Code with Error:
inner class MyReceiver : BroadcastReceiver() {
        override fun onReceive(context: Context, intent: Intent) {
            val location = intent.getParcelableExtra(LocationUpdatesService.EXTRA_LOCATION)
            if (location != null) {
                Toast.makeText(
                    this@MainActivity, Utils.getLocationText(location),
                    Toast.LENGTH_SHORT
                ).show()
            }
        }
    }

Solution:
val location = intent.getParcelableExtra(LocationUpdatesService.EXTRA_LOCATION)

Replaced above line in code with below line, you can find change heighlighted in blue:
val location=intent.getParcelableExtra<Location>(LocationUpdatesService.EXTRA_LOCATION)

2 comments:

  1. Thank you, this has helped me. It will be easier to identify if you can highlight the change.

    ReplyDelete

Popular Posts