mercredi 30 août 2023

How can I resolve this Error inflating class CheckBox

Due to the fact that import kotlinx.android.synthetic.main is stuck when uploading the sdk to the project, I have been trying to do the migration but I can't get it to work. I have seen the viewbinding examples but I also see that it is in fragments and activities. I don't know if it doesn't work because I am using a :Dialog. What I have done is the following

class FragmentPruebaBinding(var activity: Activity, internal var adapter: AdapterPrueba) : Dialog(activity, R.style.AlertDialogStyle){
   var dialog: Dialog? = null

 override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       setContentView(R.layout.fragment_prueba)

        val activity: MainActivity = activity as MainActivity

        val Nombre: TextView = findViewById(R.id.Nombre)
        val check: CheckBox =findViewById(R.id.check)
        val btn_aceptar: Button = findViewById(R.id.btn_aceptar)
        val btn_cancelar: Button = findViewById(R.id.btn_cancelar)
        val nom: String = MainActivity.dataIdentities.activeIdent.name!! + " " + MainActivity.dataIdentities.activeIdent.snam!! + " " + MainActivity.dataIdentities.activeIdent.snam2
        Nombre.text =  nom
        check.setOnClickListener {
            adapter.setEnableAseg(!check.isChecked)
            adapter.notifyDataSetChanged()
        }
. . . 
}

the xml would look like this:

<?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=".FragmentPruebaBinding">

    <LinearLayout
        android:id="@+id/LinearA"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:orientation="vertical"
        tools:ignore="MissingConstraints">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="170dp"
            android:fontFamily="@font/roboto"
            app:cardBackgroundColor="@color/color_background_cardview_seleccion_prueba"
            app:cardCornerRadius="18dp"
            app:cardElevation="5dp"
            app:cardPreventCornerOverlap="true"
            app:cardUseCompatPadding="true">

            <TextView
                android:id="@+id/Nombre"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="28dp"
                android:layout_marginTop="20dp"
                android:background="@color/color_background_cardview_seleccion_prueba"
                android:fontFamily="@font/roboto"
                android:textColor="@color/color_nombre"
                android:textSize="22sp"
                app:layout_constraintTop_toBottomOf="@id/header" />

            <TextView
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="28dp"
                android:layout_marginTop="60dp"
                android:background="@color/color_background_cardview_seleccion_prueba"
                android:text="@string/header"
                android:textColor="@color/color_nombre"
                android:textSize="15sp" />


            <CheckBox
                android:id="@+id/check"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:layout_marginTop="90dp"
                android:fontFamily="@font/roboto"
                android:paddingStart="5dp"
                android:paddingEnd="0dp"
                android:text="@string/check_text"
                android:textColor="@color/color_letra_seleccion_prueba"
                android:textSize="16sp"
                app:buttonTint="@color/color_checkox_checked"
                app:layout_constraintTop_toBottomOf="@id/Nombre" />
        </androidx.cardview.widget.CardView>

    </LinearLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/white"
        app:layout_constraintBottom_toTopOf="@+id/btns_pruebas"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/LinearA" />

    <LinearLayout
        android:id="@+id/btns_pruebas"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <Button
            android:id="@+id/btn_cancelar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:backgroundTint="@color/cancel_button"
            android:fontFamily="@font/roboto"
            android:insetTop="0dp"
            android:insetBottom="0dp"
            android:text="@string/cancel"
            android:textSize="14sp"
            app:cornerRadius="0dp"
            app:strokeColor="@color/color_datos_02"
            app:strokeWidth="0.2dp" />

        <Button
            android:id="@+id/btn_aceptar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:backgroundTint="@color/accept_button"
            android:fontFamily="@font/roboto"
            android:insetTop="0dp"
            android:insetBottom="0dp"
            android:text="@string/aceptar"
            android:textSize="14sp"
            app:cornerRadius="0dp"
            app:strokeColor="@color/color_datos_02"
            app:strokeWidth="0.1dp" />

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

but I get the following error:

 android.view.InflateException: Binary XML file line #64 in ***:layout/fragment_prueba: Binary XML file line #64 in ***:layout/fragment_prueba: Error inflating class CheckBox
                                                                                                    Caused by: android.view.InflateException: Binary XML file line #64 in ***:layout/fragment_prueba: Error inflating class CheckBox
                                                                                                    Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}, theme={InheritanceMap=[id=0x7f150003***:style/AlertDialogStyle, id=0x7f150127***:style/FioriAlertDialogStyle, id=0x7f1503d1***:style/ThemeOverlay.MaterialComponents.MaterialAlertDialog, id=0x7f150086***:style/Base.ThemeOverlay.MaterialComponents.MaterialAlertDialog, id=0x7f15009a***:style/Base.V14.ThemeOverlay.MaterialComponents.MaterialAlertDialog, id=0x7f150375***:style/ThemeOverlay.AppCompat.Dialog.Alert, id=0x7f15007c***:style/Base.ThemeOverlay.AppCompat.Dialog.Alert, id=0x7f15007b***:style/Base.ThemeOverlay.AppCompat.Dialog, id=0x7f1500a4***:style/Base.V21.ThemeOverlay.AppCompat.Dialog, id=0x7f1500b8***:style/Base.V7.ThemeOverlay.AppCompat.Dialog, id=0x7f150077***:style/Base.ThemeOverlay.AppCompat, id=0x7f1501c1***:style/Platform.ThemeOverlay.AppCompat], Themes=[***:style/AlertDialogStyle, forced, ***:style/AppTheme.NoActionBar, forced, ***:style/Theme.AppCompat.Empty, forced, android:style/Theme.DeviceDefault.Light.DarkActionBar, forced]}
                                                                                                        at android.content.res.TypedArray.getColorStateList(TypedArray.java:600)
                                                                                                        at android.widget.TextView.readTextAppearance(TextView.java:4129)
                                                                                                        at android.widget.TextView.<init>(TextView.java:1128)
                                                                                                        at android.widget.Button.<init>(Button.java:166)
                                                                                                        at android.widget.CompoundButton.<init>(CompoundButton.java:104)
                                                                                                        at android.widget.CheckBox.<init>(CheckBox.java:71)
                                                                                                        at android.widget.CheckBox.<init>(CheckBox.java:67)
                                                                                                        at androidx.appcompat.widget.AppCompatCheckBox.<init>(AppCompatCheckBox.java:79)
                                                                                                        at com.google.android.material.checkbox.MaterialCheckBox.<init>(MaterialCheckBox.java:231)
                                                                                                        at com.google.android.material.checkbox.MaterialCheckBox.<init>(MaterialCheckBox.java:227)
                                                                                                        at com.google.android.material.theme.MaterialComponentsViewInflater.createCheckBox(MaterialComponentsViewInflater.java:49)
                                                                                                        at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:145)
                                                                                                        at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1569)
                                                                                                        at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1620)
                                                                                                        at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1065)
                                                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1001)
                                                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
                                                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
                                                                                                        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
                                                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
                                                                                                        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
                                                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
                                                                                                        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
                                                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
                                                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
                                                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:485)
                                                                                                        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:469)
                                                                                                        at android.app.Dialog.setContentView(Dialog.java:597)
                                                                                                        at ***.FragmentPruebaBinding.onCreate(FragmentPruebaBinding.kt:39)

the line 39 is:

setContentView(R.layout.fragment_aseguradora)

I tried this tutorial but to no avail either. I don't know what I'm missing https://developer.android.com/topic/libraries/view-binding/migration

Thanks for any help.




Aucun commentaire:

Enregistrer un commentaire