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 ?
I tried below solution and worked for me. press crtl + shift + alt + s to enter project structure. In Project Settings select project . Then in Project SDK click on your java version and select Kotlin instead.
If you still see the unresolved reference error after fixing the problem, try to build your Android application with Command + F9 for Mac or Control + F9 for Windows and Linux. The error should disappear after the build is completed.
In my case removing import android.R
solved the issue.
remove import android.R
from imports which might be imported automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With