java - Kotlin Extensions - Inflate Custom Views
问题描述
I'm new to kotlin, I Have an adapter class and I need to inflate a view. but recently I'm facing an error saying "Unresolved reference: R"
Like in the image below :
So, how can I inflate this view? I have imported the following:
import kotlinx.android.synthetic.main.slide_layout.view.*
But I can't figure out what should i do next, I searched everywhere, but they all seem outdated! so what should i do? Thank you!
解决方案
There are two possible issues i can think of,
- The first is a missing import to the R class, if your adapter is in an inner package from your domain package name, i.e.
- assume this is the domain package 'your.doamin.package'
- if adapter is not in that package i.e. adapter is in 'your.domain.package.adapter' then you need to import the R class into that file, i.e write this import statement
import your.domain.package.R
That should fix your problem for this scenario
- If you have already done '1' above then the other issue is, Sometimes Android studio just misbehaves, so close the file and clean and build your project by first clicking, Build -> Clean Project, once the build is done reopen that file.
推荐阅读
- python - how to resolve this error InvalidArgumentError: sequential_6_input:0 is both fed and fetched
- php - How to update multiple MySQL table entries with different id?
- jquery - 如何拆分方括号内的字符串并使用JQUERY放入数组中
- javascript - 以编程方式修改url 以添加 "?example-text=50" 和前缀 "
" - javascript - 如何使用整数作为 JSON 对象键
- java - 运行 Spring Boot JPA 测试时,数据库中没有保留任何值
- python - 如何在 Jenkins 的无 GUI 模式下在锁定的远程机器上成功运行 AutoIT 脚本?
- python - AttributeError:“复合”对象在 vpython.py 中没有属性“_origin”
- python - ds = data_set(sys.argv[1]) IndexError: 列表索引超出范围
- docker - 使用 docker 的 Traefik 配置文件位置