欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-03-08 16:13:40
...

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使用的注解处理器