DataBinding报错:cannot find the setter for attribute xxx with parameter type xxx

https://blog.csdn.net/Dream2076/article/details/84305310

报错信息如下:

C:\Android\projects\LazySheep\app\build\generated\source\apt\debug\top\littlefogcat\lazysheep\DataBinderMapperImpl.java:18: 错误: 找不到符号
import top.littlefogcat.lazysheep.databinding.UserProfileLayoutBindingImpl;
                                             ^
  符号:   类 UserProfileLayoutBindingImpl
  位置: 程序包 top.littlefogcat.lazysheep.databinding

> Task :app:buildInfoGeneratorDebug

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> android.databinding.tool.util.LoggedErrorException: Found data binding errors.
  ****/ data binding error ****msg:Cannot find the setter for attribute 'app:username' with parameter type androidx.lifecycle.LiveData<top.littlefogcat.lazysheep.model.UserProfile> on android.widget.TextView.
  file:C:\Android\projects\LazySheep\app\src\main\res\layout\user_profile_layout.xml
  loc:20:28 - 20:56
  ****\ data binding error ****


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2s

在检查了代码的确无误之后,看到这篇文章:https://blog.csdn.net/Dream2076/article/details/84305310
原来是没有添加kapt插件,添加之后就能正常运行了。

kapt的介绍在此:https://www.kotlincn.net/docs/reference/kapt.html

kapt 即 Kotlin annotation processing tool(Kotlin 注解处理工具)缩写。
在 Kotlin 中通过 kapt 编译器插件支持注解处理器(参见JSR 269)。
简而言之,你可以在 Kotlin 项目中使用像 Dagger 或者 Data Binding 这样的库。

也就是说,kapt是kotlin使用的注解处理器

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值