Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved reference in kotlin with id and activity_main

Tags:

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 ?

like image 832
Hugo Sohm Avatar asked Oct 29 '19 16:10

Hugo Sohm


People also ask

How do you solve unresolved reference Kotlin?

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.

How to fix unresolved reference android Studio?

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.


2 Answers

In my case removing import android.R solved the issue.

like image 99
SkorpEN Avatar answered Oct 12 '22 19:10

SkorpEN


remove import android.R from imports which might be imported automatically.

like image 33
Pravin Desai Avatar answered Oct 12 '22 19:10

Pravin Desai