是的,我的方法引发了'java.lang.NullPointerException'异常,是的,我用Google搜索和加深了有关NullPointerException的主题。但是我仍然无法解决我的错误。简要说明:我正在创建小型游戏,您应该按递增的顺序单击带阴影的数字。它正在运行,没有任何错误。我的适配器随机播放并正确放置了有限的数字。但是当我按下按钮时,我无法处理点击。但是,当我调试时,它给了我类似'Line 36 in LevelAdapter.kt No executable code found at line 36 in class com.example.ganz.minigamesortnumbers.LevelAdapter$MyViewHolder$bind$1 Suspend: thread'
的错误(例如线程在LevelAdapter.kt的第15、19、26和36行,LevelActivity.kt的第31和47行也有错误)和{{ 1}}。要解决最后一个问题,建议我单击鼠标右键->“查看为->”,然后勾选“ toString”。但是最初是打勾的。顺便说一句,我解开并再次打勾。没关系,它对我没有帮助。那么,我在哪里犯了错误?
LevelActivity.kt
'Method threw 'java.lang.NullPointerException' exception. Cannot evaluate com.example.ganz.minigamesortnumbers.LevelAdapter$MyViewHolder.toString()'
LevelAdapter.kt
package com.example.ganz.minigamesortnumbers
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.widget.Toast
import kotlinx.android.synthetic.main.level.*
import java.util.*
import kotlin.collections.ArrayList
class LevelActivity : AppCompatActivity(), LevelAdapter.Listener {
private var numbersList: ArrayList<LevelModel>? = null
private var numbersAdapter: LevelAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.level)
setSupportActionBar(tbr_level)
shuffleNumbers(64.toString())
initRecycler()
btn_back.setOnClickListener { finish() }
Toast.makeText(this, "Heeeeey!!", Toast.LENGTH_SHORT).show()
}
private fun shuffleNumbers(rangeOfNumbers: String) {
val arrTest = arrayOfNulls<Int>(1000)
for (i in arrTest.indices) {
arrTest[i] = i
}
Arrays.asList(arrTest).shuffle()
numbersList = ArrayList()
for (i in 0 until rangeOfNumbers.toInt()) {
numbersList!!.add(arrTest[i]?.let { LevelModel(it.toString()) }!!)
}
numbersList!!.shuffle()
}
private fun initRecycler() {
val layoutManager: RecyclerView.LayoutManager =
GridLayoutManager(this, 8)
rv_level.layoutManager = layoutManager
numbersAdapter = LevelAdapter(numbersList!!, this)
rv_level.adapter = numbersAdapter
}
override fun onItemClick(levelModel: LevelModel) {
tv_level_title.text = "It is working!!"
Toast.makeText(
this,
"${levelModel.randomNumbers} Hee",
Toast.LENGTH_SHORT).show()
}
}