Issue
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
Here the MainActivity.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()
}
}
}
Here the activity_main.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 ?
Solution
In my case removing import android.R
solved the issue.
Answered By - SkorpEN
Answer Checked By - Cary Denson (JavaFixing Admin)