# Chapter 7 Reference Error

**URL:** <https://forums.kodeco.com/t/chapter-7-reference-error/77764>\
**Category:** Android Apprentice\
**Created:** [July 31, 2019, 3:34am UTC](https://forums.kodeco.com/t/chapter-7-reference-error/77764 "2019-07-31T03:34:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![andkot1](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/andkot1/32/81494_2.png) [@andkot1](https://forums.kodeco.com/u/andkot1)\
**Post date:** [July 31, 2019, 3:34am UTC](https://forums.kodeco.com/t/chapter-7-reference-error/77764/1 "2019-07-31T03:34:18Z")

</div>

The code you provided throws an “unresolved reference” error on line 28 of chapter 7.

28 listsRecyclerView = findViewById(R.id.lists\_recyclerview)

“lists\_recyclerview” throws an error in Android Studio 3.4.2

What needs to be changed in the code to allow this to compile?

Thanks!

---

<div class="post-metadata">

**Author:** ![ericwastaken](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ericwastaken/32/103488_2.png) [@ericwastaken](https://forums.kodeco.com/u/ericwastaken)\
**Post date:** [July 31, 2019, 4:08pm UTC](https://forums.kodeco.com/t/chapter-7-reference-error/77764/2 "2019-07-31T16:08:30Z")

</div>

Thanks for your comment. I am looping in the book team to get you an answer. Thanks! - Eric

---

<div class="post-metadata">

**Author:** ![daemonic\_daz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/daemonic_daz/32/108563_2.png) [@daemonic\_daz](https://forums.kodeco.com/u/daemonic_daz)\
**Post date:** [July 31, 2019, 6:43pm UTC](https://forums.kodeco.com/t/chapter-7-reference-error/77764/3 "2019-07-31T18:43:06Z")

</div>

Hi @andkot,

Welcome to the forums and sorry to hear you’re running into errors in the Chapter 7 sample code.

The error doesn’t appear for me in the final project using Android Studio 3.4.2 on macOS. That doesn’t mean there isn’t a problem though.

I’m wondering if there’s a set of steps you followed to get the error to show, also is your machine is running a different OS to mine?

If you can provide any of this information, as well as anything else relevant that will be helpful to continue figuring out what is happening.

Thanks,

Darryl

---

<div class="post-metadata">

**Author:** ![andkot1](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/andkot1/32/81494_2.png) [@andkot1](https://forums.kodeco.com/u/andkot1)\
**Post date:** [July 31, 2019, 9:57pm UTC](https://forums.kodeco.com/t/chapter-7-reference-error/77764/4 "2019-07-31T21:57:10Z")

</div>

Hello Darryl,

Thanks for helping!

Ok so obvious differences first:  
Win10  
Gradle 5.1.1

The libraries are all different if you use gradle 5.1.1 so I think the problem may be here:

* * *

import android.os.Bundle  
import com.google.android.material.snackbar.Snackbar  
import androidx.appcompat.app.AppCompatActivity  
import android.view.Menu  
import android.view.MenuItem  
import androidx.recyclerview.widget.LinearLayoutManager  
import androidx.recyclerview.widget.RecyclerView

import kotlinx.android.synthetic.main.activity\_main.\*

* * *

When I run the final project with the version of gradle that you released it with, it compiles fine. Only when I use the code with newer libraries and gradle 5.1.1, the compiler throws the Unresolved reference error on “lists\_recylerview”.

Thank you again.

---

<div class="post-metadata">

**Author:** ![daemonic\_daz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/daemonic_daz/32/108563_2.png) [@daemonic\_daz](https://forums.kodeco.com/u/daemonic_daz)\
**Post date:** [August 3, 2019, 12:19pm UTC](https://forums.kodeco.com/t/chapter-7-reference-error/77764/5 "2019-08-03T12:19:00Z")

</div>

Hey @andkot1,

Thank you for the extra information, it’s useful to know.

I opened the project again and updated it to use gradle 5.1.1 and the AndroidX libraries. This should be similar to the setup of the project on your machine.

The project compiles and the app appears in the emulator.

The next step we can try is looking at your project to see what could be different. Is it possible to upload your project somewhere for us to view?

Thank you,

Darryl

---

<div class="post-metadata">

**Author:** ![andkot1](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/andkot1/32/81494_2.png) [@andkot1](https://forums.kodeco.com/u/andkot1)\
**Post date:** [August 3, 2019, 8:13pm UTC](https://forums.kodeco.com/t/chapter-7-reference-error/77764/6 "2019-08-03T20:13:36Z")

</div>

Here you be:

> **[File Dropper - Online file sharing](https://www.filedropper.com/listmakerandkot1)**
>
> Online file sharing

Again thank you so much for taking the time to help me on this, very frustrating after making very good progress to get stuck, and not understanding why.

If its worth anything, i dont think its a typo error, i can recreate this error by using your final project itself, then updating gradle, then it throws the error. But let me know…

THANKS!!

---

<div class="post-metadata">

**Author:** ![daemonic\_daz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/daemonic_daz/32/108563_2.png) [@daemonic\_daz](https://forums.kodeco.com/u/daemonic_daz)\
**Post date:** [August 3, 2019, 9:13pm UTC](https://forums.kodeco.com/t/chapter-7-reference-error/77764/7 "2019-08-03T21:13:42Z")

</div>

Brilliant!

Looking at the project, there’s a few things.

1. In **content\_main.xml** the RecyclerView doesn’t have an id. Without an id the app can’t find the recyclerView and throws an error. Fix this by adding the **id** to the RecyclerView in **content\_main.xml** like so:

2. The **list\_selection\_view\_holder.xml** contains two TextViews, only the TextView with the id **itemNumber** is needed. The layout margin for the TextView is also set to **16** , change this to **16dp**. The **dp** lets the app know what measurement type to use to set up the TextView margins.

The TextView in **list\_selection\_view\_holder.xml** will look like:

```
   <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:id="@+id/itemNumber"
        android:layout_margin="16dp"/> <--- Make sure the dp is added here

```

With the changes made, run the app. The errors will no longer appear.

I hope this helps you, let us know how you get on.

Thanks,

Darryl

---

<div class="post-metadata">

**Author:** ![andkot1](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/andkot1/32/81494_2.png) [@andkot1](https://forums.kodeco.com/u/andkot1)\
**Post date:** [August 4, 2019, 12:56am UTC](https://forums.kodeco.com/t/chapter-7-reference-error/77764/8 "2019-08-04T00:56:09Z")

</div>

Darryl,

1. You da man.

2. I cant possibly take accountability for this so I’m going to blame Hadi Hariri.

-eof-

---

<div class="post-metadata">

**Author:** ![daemonic\_daz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/daemonic_daz/32/108563_2.png) [@daemonic\_daz](https://forums.kodeco.com/u/daemonic_daz)\
**Post date:** [August 4, 2019, 4:46pm UTC](https://forums.kodeco.com/t/chapter-7-reference-error/77764/9 "2019-08-04T16:46:42Z")

</div>

Sounds like everything is ok now. 🙂

We hope you enjoy the rest of the book!

Darryl
