-1

I keep getting a runtime error when launching my activity and it says androidx.appcompat.widget.AppCompatImageView cannot be cast to android.widget.TextView?

    Process: com.jaygohel.ubereatsclone, PID: 5010
    java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageView cannot be cast to android.widget.TextView
        at com.jaygohel.ubereatsclone.adapter.HomeAdapter$viewHolder.<init>(HomeAdapter.java:50)
        at com.jaygohel.ubereatsclone.adapter.HomeAdapter.onCreateViewHolder(HomeAdapter.java:31)
        at com.jaygohel.ubereatsclone.adapter.HomeAdapter.onCreateViewHolder(HomeAdapter.java:17)
        at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7078)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6235)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
        at androidx.recyclerview.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:561)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
        at androidx.recyclerview.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
        at android.view.View.layout(View.java:16953)
        at android.view.ViewGroup.layout(ViewGroup.java:5579)
        at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1873)
        at android.view.View.layout(View.java:16953)
        at android.view.ViewGroup.layout(ViewGroup.java:5579)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:396)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
        at android.view.View.layout(View.java:16953)
        at android.view.ViewGroup.layout(ViewGroup.java:5579)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:2001)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1844)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1753)
        at android.view.View.layout(View.java:16953)
        at android.view.ViewGroup.layout(ViewGroup.java:5579)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:396)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
        at android.view.View.layout(View.java:16953)
        at android.view.ViewGroup.layout(ViewGroup.java:5579)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:2001)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1844)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1753)
        at android.view.View.layout(View.java:16953)
        at android.view.ViewGroup.layout(ViewGroup.java:5579)
        at android.app.ActivityThread.main(ActivityThre
I/Process: Sending signal. PID: 5010 SIG: 9

Main Activity.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/listProduct"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> 

listitem.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/listProduct"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

I have also trying to clean project re-build it. but this also not work. i can't undestarnend whatissue will be genrate in project.

Jay Gohel
  • 1
  • 2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 30 '21 at 03:34
  • Can you please tell us how is this question related to Firebase? – Alex Mamo Oct 30 '21 at 06:58

1 Answers1

0

It's hard to say without seeing your homeAdapter class. Anyway probabily, it's caused by a wrong id.

Ansol
  • 95
  • 1
  • 11
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 29 '21 at 15:27