【发布时间】:2017-01-07 03:33:33
【问题描述】:
我正在努力让 Android Binding Library 与 Kotlin 一起工作。我想要实现的是向我的 Presenter 类发送一个 onClick 事件。我所做的是:
- 在模块的 gradle 文件上启用数据绑定:
dataBinding {enabled = true} - 导入数据绑定编译器:
kapt 'com.android.databinding:compiler:2.0.0-beta6' - 生成存根:
kapt {generateStubs = true} -
MainPresenter.kt 上的实现方法:
fun onClickEditProfile () { log("method you hoped to get called was called") mView!!.getContext().snackbar("received event: onClickEditProfile via data binding, this is awesome").show() } -
准备布局:
<layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <data> <variable name="presenter" type="br.com.tyllt.presenter.MainPresenter" /> </data> <com.github.clans.fab.FloatingActionButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="@{() -> presenter.onClickEditProfile()}" android:src="@drawable/ic_edit" app:fab_colorNormal="@color/colorPrimary" app:fab_colorPressed="@color/colorPrimaryDark" app:fab_hideAnimation="@anim/fab_scale_down" app:fab_label="Edit Profile" app:fab_size="mini" /> </layout>
问题是,当我生成 apk 时,出现以下异常:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
java.lang.IllegalArgumentException:指定为非空的参数为空:方法org.jetbrains.kotlin.annotation.RoundEnvironmentWrapper.getElementsAnnotatedWith,参数a
有什么想法吗?
【问题讨论】:
-
粘贴你的 build.gradle 文件
标签: android data-binding kotlin android-databinding