简体   繁体   English

java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageView 不能转换为 android.widget.TextView

[英]java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageView cannot be cast to android.widget.TextView

I keep getting a runtime error when launching my activity and it says androidx.appcompat.widget.AppCompatImageView cannot be cast to android.widget.TextView?启动我的活动时,我不断收到运行时错误,它说 androidx.appcompat.widget.AppCompatImageView 不能转换为 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

<?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

<?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.我无法理解项目中会产生什么问题。

It's hard to say without seeing your homeAdapter class.如果没有看到您的 homeAdapter 类,很难说。 Anyway probabily, it's caused by a wrong id.无论如何,这是由错误的ID引起的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我不断收到错误 java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageView cannot be cast to android.widget.TextView - i keep getting the error java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageView cannot be cast to android.widget.TextView java.lang.ClassCastException:android.widget.TextView无法转换为android.widget.EditText - java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText java.lang.ClassCastException:android.widget.ScrollView无法强制转换为android.widget.TextView - java.lang.ClassCastException: android.widget.ScrollView cannot be cast to android.widget.TextView java.lang.ClassCastException:android.widget.ImageButton无法转换为android.widget.TextView - java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.TextView java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageButton 不能转换为 android.widget.Button - java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageButton cannot be cast to android.widget.Button java.lang.ClassCastException:android.support.constraint.ConstraintLayout无法转换为android.widget.TextView - java.lang.ClassCastException: android.support.constraint.ConstraintLayout cannot be cast to android.widget.TextView java.lang.ClassCastException:android.widget.TextView - java.lang.ClassCastException: android.widget.TextView 如何修复使用:java.lang.ClassCastException: androidx.appcompat.widget.AppCompatTextView 不能转换为 android.widget.Button - how to fix aused by: java.lang.ClassCastException: androidx.appcompat.widget.AppCompatTextView cannot be cast to android.widget.Button java.lang.RuntimeException:在类 androidx.appcompat.widget.AppCompatImageView 上发现名称 isImportantForAccessibility 的 getter 冲突 - java.lang.RuntimeException: Found conflicting getters for name isImportantForAccessibility on class androidx.appcompat.widget.AppCompatImageView 错误 - java.lang.ClassCastException:com.google.android.material.appbar.AppBarLayout 无法转换为 androidx.appcompat.widget.Toolbar - Error - java.lang.ClassCastException:com.google.android.material.appbar.AppBarLayout cannot be cast to androidx.appcompat.widget.Toolbar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM