android - Function unresolved reference in main activity
问题描述
so I'll try to explain my problem this time without pasting you 400 lines of code.
I have a custom view that im using in my main activity (com.company.app.common.ui.view1), in my main activity it's imported properly as follow
import com.company.app.common.ui.view1
Inside view1 i have a function defined in the constructor
fun updateItems(items: List<Item>){}
Item is an object I have modeled properly and the function has no errors.
But when I try to call it in my main activity using
view1.updateItems(items)
I get an unresolved reference on updateItems
.
the function is supposedly public by default if im not wrong, can anyone help? Thanks
解决方案
看起来您正在尝试在类而不是实例上调用该方法(获取实例的一种方法是通过构造函数创建它myView1 = view1(...)
,然后您可以在其上调用该方法myView1.updateItems(items)
还有两点:
- 无需发布所有代码,只需发布片段(仅与问题相关的代码),将不相关的代码替换为
...
并保留括号 - 在我的回答中,我假设(根据你写的)
view1
应该是一个类/对象,最好将它的名字大写,这样它就不会与实例混淆
推荐阅读
- javascript - 转到 toString 然后返回时的正则表达式意外行为
- php - 无法在 laravel 5.5 控制器中检索 file_get_contents('php://input')
- apache-spark - 使用 spark 更新 ElasticSearch 中的嵌套对象
- java - 实现一个 kotlin 泛型函数,从复杂的 java 对象中检索特定字段
- python - python和yaml提取某些yaml字段的值
- c# - System.AccessViolationException 从 C# 调用 c++ 函数
- react-native - 如何从身份证和护照中扫描和提取数据
- c++ - C++ 我应该如何解释函数参数 long(*pPointer)(OtherClass *const, long)?
- mysql - 如何在 Pentaho Server 中创建 MySQL 数据连接
- mysql - 如何从 MYSQL 的特定用户组中获得最低价格