gpt4 book ai didi

kotlin - kotlin.NotImplementedError:未实现操作:未实现

转载 作者:行者123 更新时间:2023-12-02 12:42:25 28 4
gpt4 key购买 nike

服务器JSON使用retrofit2rxjava2进行数据解析。转到CompanyAdapter类时,数据获取并成功存储在List中,然后给出上述错误。

MainActivity.kt

 private fun fetchData(){

val retrofit = APIClient.apIClient
if (retrofit != null) {
api = retrofit.create(APIInterface::class.java)
}
compositeDisposable!!.add(api.getCompanyData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe{displayData(it.company)
}
)
}

private fun displayData(companyList : List<Company>) {

adapter = CompanyAdapter(this, companyList)
rvCompany.adapter = adapter

}

ComnyAdapter.kt
class CompanyAdapter(internal var context: Context, internal var companyList: List<Company>)
:RecyclerView.Adapter<CompanyAdapter.CompanyViewHolder>()
{
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): CompanyViewHolder {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.

val itemView = LayoutInflater.from(p0.context).inflate(R.layout.list_view_item,p0,false)

return CompanyViewHolder(itemView)
}

override fun getItemCount(): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
return companyList.size
}

override fun onBindViewHolder(p0: CompanyViewHolder, p1: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.


p0.bindModel(companyList[p1])
}

inner class CompanyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){

val radioButton : RadioButton = itemView.findViewById(R.id.rbCompanyName)

fun bindModel(company: Company){

radioButton.text = company.Cmp_Name
}
}
}

最佳答案

原因很简单:当您使用TODO执行一行时,它会抛出Not Implemented Exception
只需从代码中删除所有TODO即可:

class CompanyAdapter(internal var context: Context, internal var companyList: List<Company>)
:RecyclerView.Adapter<CompanyAdapter.CompanyViewHolder>()
{
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): CompanyViewHolder {
val itemView = LayoutInflater.from(p0.context).inflate(R.layout.list_view_item,p0,false)

return CompanyViewHolder(itemView)
}

override fun getItemCount(): Int {

return companyList.size
}

override fun onBindViewHolder(p0: CompanyViewHolder, p1: Int) {
p0.bindModel(companyList[p1])
}

inner class CompanyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){

val radioButton : RadioButton = itemView.findViewById(R.id.rbCompanyName)

fun bindModel(company: Company){
radioButton.text = company.Cmp_Name
}
}
}

关于kotlin - kotlin.NotImplementedError:未实现操作:未实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55451635/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com