unresolved reference activity_main

Writing this blog post today because a lot of the blog posts regarding this error message are out of date. If you happen to be getting started on a brand new Android Studio project using Kotlin, and you run into the error message “unresolved reference activity_main,” here’s the problem: your blank activity is probably importing android.R instead of import kotlinx.android.synthetic.main.activity_main.* in your MainActivity.kt file. So here is all you need to do…

First, delete the following line of code:

import android.R

And replace it with this line of code:

import kotlinx.android.synthetic.main.activity_main.*

And that’s all there is to it! Happy coding 🙂

 

topherPedersen