为什么我这段代码会报错呢class ListViewTest : AppCompatActivity() { private val data = listOf("Apple","Banana","Orange","Watermelon", "Pear","Grape","Pineapple","Strawberry","Cherry","Mango", "Apple","Banana","Orange","Watermelon","Pear","Grape", "Pineapple","Strawberry","Cherry","Mango") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.listview_layout) val adapter = ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,data) listView.adpter = adapter } }
时间: 2023-05-12 09:07:15 浏览: 114
可能是因为最后一行代码中的 "adpter" 拼写错误,应该改为 "adapter"。正确的代码如下:
class ListViewTest : AppCompatActivity() {
private val data = listOf("Apple","Banana","Orange","Watermelon",
"Pear","Grape","Pineapple","Strawberry","Cherry","Mango",
"Apple","Banana","Orange","Watermelon","Pear","Grape",
"Pineapple","Strawberry","Cherry","Mango")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.listview_layout)
val adapter = ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,data)
listView.adapter = adapter
}
}
阅读全文