I'm actually creating a new app in kotlin to display an xml file in boxes with the informations formatted

To problem is that when I'm building the app, there is the activity_main, the id that return "Unresolved reference"

Unresolved reference: id
Unresolved reference: id

这里是主要活动.kt

package com.example.instantsystem

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.ListView
import java.io.IOException

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val listView = findViewById<ListView>(id.listView)
        var employees: List<Employee>? = null
        try {
            val parser = XmlPullParserHandler()
            val istream = assets.open("employees.xml")
            employees = parser.parse(istream)

            val adapter = ArrayAdapter(this, R.layout.simple_list_item_1, employees)
            listView.adapter = adapter

        } catch (e: IOException) {
            e.printStackTrace()
        }
    }
}

这里是活动的主要部分.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
    tools:context="com.example.instantsystem.MainActivity">

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

    </ListView>

</android.support.constraint.ConstraintLayout>

I don't understand the error, I imported the package and defined it in xml. What is wrong in my code ?

推荐答案

在我的例子中,go 掉import android.R就解决了问题.

Kotlin相关问答推荐

Spring Boot Bean验证器未触发

在Kotlin中求n个ClosedRange实例相交的最常用方法是什么?

数据流弹性模板失败,出现错误&未知非复合转换urn";

如何在Spring Boot中注册新的集合工厂

有什么方法可以要求在 kotlin 中的类型参数上进行注释?

如何在 kotlin 中创建自定义迭代器并添加到现有类?

有没有一种简单的方法可以将数组/列表中的每个元素相互相乘 - Kotlin?

如何将字符串格式化为电话号码kotlin算法

在 Kotlin 中,::class.simpleName是做什么的?

如何有效地填充 Gradle Kotlin DSL 中的额外属性?

在 Kotlin 中,当枚举类实现接口时,如何解决继承的声明冲突?

作为 Kotlin 中的函数的结果,如何从 Firestore 数据库返回列表?

将协同路由调用放在存储库或ViewModel中哪个更好?

如何在 Jetpack Compose 的 LazyColumn/LazyRow 中禁用和启用滚动?

在 Kotlin 函数上使用 Mokito anyObject() 时,指定为非 null 的参数为 null

什么是 Kotlin 等价于 Class<?>

Kotlin - 如果不为空,则使用修改后的 Obj props 覆盖 Obj props

如何在不绑定ViewModel(MVVM)中的UI的情况下使用android导航?

Android Compose 生产准备好了吗?

Kotlin反射不可用