Why can't pass null value? how can fix it? I can't find any hint from Document.
ERROR
****/ data binding error ****msg:cannot find method onClick(java.lang.Object, java.lang.Object) in class kr.co.app.MyActivity.MyListener file:/Users/jujaeho/projects/app/src/main/res/layout/activity_my.xml loc:24:71 - 24:106 ****\ data binding error ****
CODE
class MyActivity {
interface MyListener {
fun onClick(abc: ABC?, count: Int?)
}
}
<layout>
<data>
<variable
name="handler"
type="kr.co.app.MyActivity.MyListener" />
</data>
<View
...
android:onClick="@{() -> handler.onClick(null, null)}" />
</layout>
I just encountered this problem today, and what I did basically was to cast the null
parameters to the types expected in the method parameters. In your case, this should be something like:
<layout>
<data>
<import type="ABC" /> // just an illustration, specify the full package
<variable
name="handler"
type="kr.co.app.MyActivity.MyListener" />
</data>
<View
...
android:onClick="@{() -> handler.onClick((ABC) null, (int) null)}" />
</layout>
I am not sure about the int
casting, but you can try it or use the Integer
wrapper class for casting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With