Daniele Segato
08/20/2018, 8:10 AMUnresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public fun `Activity;`.findNavController(viewId: Int): `NavController;` defined in androidx.navigation
public fun `View;`.findNavController(): `NavController;` defined in androidx.navigation
This means my previously working code doesn't compile anymore on this stuff:
view.setOnClickListener {
it.findNavController().navigate(somewhere)
}
cause it cant resolve findNavController()
extension function.
I think it's a collision?
Checked the source code
package androidx.navigation
import android.view.View
/**
* Find a [NavController] associated with a [View].
*
* Calling this on a View not within a [NavHost] will result in an
* [IllegalStateException]
*/
fun View.findNavController(): NavController =
Navigation.findNavController(this)
and
package androidx.navigation
import android.app.Activity
import android.support.annotation.IdRes
/**
* Find a [NavController] given the id of a View and its containing
* [Activity].
*
* Calling this on a View that is not a [NavHost] or within a [NavHost]
* will result in an [IllegalStateException]
*/
fun Activity.findNavController(@IdRes viewId: Int): NavController =
Navigation.findNavController(this, viewId)
these two collide I think and when you import androidx.navigation.findNavController
it doesn't know which one to import?Navigation.findNavController(it)
. I've asked the question to learn more about this kind of situation.
How to handle collisions like this, how to avoid them etc...louiscad
08/20/2018, 8:16 AMit
in setOnClickListener { ... }
nullable? Try with safe call (it?.findNavController()
)Daniele Segato
08/20/2018, 8:29 AMView!
anyway, so yeah, can be Nullable but basically never is. And if i use it!!
or it?
nothing change