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 for your comment. I am looping in the book team to get you an answer. Thanks! - Eric
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 for helping!
Ok so obvious differences first:
The libraries are all different if you use gradle 5.1.1 so I think the problem may be here:
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.
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?
Here you be:
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…
Looking at the project, there’s a few things.
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:
android:id="@+id/lists_recyclerview" <--- Add this attribute
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:
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.
Sounds like everything is ok now.
We hope you enjoy the rest of the book!