Chapter 10, problem with runnig final code

Hi, I did evething on chapter 10 and my program fails after adding task to ListDetailActivity I got “ListMaker has stopped” in log I’ve:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.danieldominiak.listmaker, PID: 15365
java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
at com.example.danieldominiak.listmaker.ListItemViewHolder.(ListItemViewHolder.kt:8)
at com.example.danieldominiak.listmaker.ListItemsRecyclerViewAdapter.onCreateViewHolder(ListItemsRecyclerViewAdapter.kt:11)
(…)

Thanks in advise

@daemonic_daz Can you please help with this when you get a chance? Thank you - much appreciated! :]

Thank you @shogunkaramazov

Hi @dnd. Sorry to hear you’re having issues.

Judging from the log, the app is using a LinearLayout as a TextView. That’s why it fails with the following error:

java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView

The log also says it’s happening in ListItemViewHolder.kt.

My advice to fix the problem is to check a TextView is setup in ListItemViewHolder.kt. If there is, make sure the TextView uses the correct id from the view holder xml layout.

Let me know how you get on. If the problem still continues we can look at alternative solutions.

Darryl

Hi, thank you for your answer, I was looking only on code side, Iknew the problem is with casting object, but I didnt check names of items. I thought that if they are not red in code they are ok ;).
The problem was in my task_view_holder.xml file, I put the same name (“textview_task”) for two items: for container LinearLayout and for its object TextView.
I’ve change name for LinearLayout and everything is ok. ;).

Taking advantage of the opportunity, I have one more question: I’ve loaded yours final version program of chapter 10 and I’m trying to run it but I’ve error on building “ERROR: Failed to find target with hash string ‘android-26’”. I know I can install ‘android-26’ and later 26.02 …, But is there any possibility to change android version avoiding downloading libraries?

@daemonic_daz Do you have any feedback about this? Thank you - much appreciated! :]

@dnd Glad to hear everything is working now. :slight_smile:

If I understand right. You want to change the version of android in the final project for chapter 10. In the aim to avoid downloading more libraries.

It’s possible to do. You need to update the gradle.build file for your app.

Open the file and change the compileSdkVersion, and targetSdkVersion values. to a version of your choice.

The values adhere to the API levels set by Android. There’s a list of them at Codinomes, tags e números de build  |  Android Open Source Project

Thanks,

Darryl