[英]Unresolved Reference on recyclerView not working?
I've been building a stock application with push notifications that I found online.我一直在用我在网上找到的推送通知构建一个股票应用程序。 { Link }. { 链接}。 I've had several issues that I have came across, that I have found answers to and fixed... However I cannot figure out what the issue is here.我遇到了几个问题,我已经找到了答案并修复了......但是我无法弄清楚这里的问题是什么。 This is the problem from my MainActivity这是我的 MainActivity 的问题
private fun setupRecyclerView() {
with(recyclerView){
layoutManager = LinearLayoutManager(this@MainActivity)
adapter = mAdapter
addItemDecoration(DividerItemDecoration(recyclerView.context, DividerItemDecoration.VERTICAL))
}
}
What am I overlooking?我在看什么? The issue with says "not enough information to infer type variable R."问题是“没有足够的信息来推断类型变量 R”。 followed by (recyclerView) "unresolved reference: recyclerView" although it's stated in my layout as @+id/recyclerView其次是(recyclerView)“未解决的参考:recyclerView”,尽管它在我的布局中声明为@+id/recyclerView
Layout Below下面的布局
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Adjuest the code as follows.调整代码如下。
private val pusher = Pusher("PUSHER_KEY", options)
private val channel = pusher.subscribe("stock-channel")
private lateinit var recyclerView : RecyclerView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
recyclerView = findViewById(R.id.recyclerView)
setupPrefs()
pusher.connect()
setupRecyclerView()
setupPusherChannels()
setupPushNotifications()
}
Now it will work for you.现在它将为您工作。 The issue was you are using an old tutorial that use syntatic sugar for view id's.问题是您正在使用一个旧教程,该教程使用语法糖作为视图 ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.