Ошибка надувания класса androidx.constraintlayout.widget.ConstraintLayoutaintLayout правильными реализациями и версиями androidx - PullRequest
0 голосов
/ 28 февраля 2020

Я пытался реализовать RecyclerView, чтобы заполнить записи, сохраненные в базе данных Firebase.

Когда я запускаю свое приложение, я получаю сообщение об ошибке:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.price, PID: 21096
    android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayoutaintLayout
    Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayoutaintLayout
    Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.constraintlayout.widget.ConstraintLayoutaintLayout" on path: DexPathList[[zip file "/data/app/com.example.price-RzfjA-3DV5y8h2WztAw65A==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.price-RzfjA-3DV5y8h2WztAw65A==/lib/x86, /data/app/com.example.price-RzfjA-3DV5y8h2WztAw65A==/base.apk!/lib/x86, /system/lib, /vendor/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)

Все остальные сообщения, которые я читаю рекомендуем обновить до реализации 'androidx.constraintlayout: constraintlayout: 1.1.3' и заменить 'androidx.constraintlayout.ConstraintLayout' на 'androidx.constraintlayout.widget.ConstraintLayout', что я и сделал.

Моя активность is:

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.ImageButton
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.database.ValueEventListener
import com.google.firebase.storage.FirebaseStorage


class CommunityDisplay : AppCompatActivity() {
    companion object {
        private val TAG = "CommunityDisplay"
    }

    private lateinit var fStorage: FirebaseStorage
    private lateinit var fDatabase: FirebaseDatabase
    private lateinit var postAdapter: PostAdapter
    private var postList : ArrayList<Post> = ArrayList<Post>()

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

        // Set up button listeners
        val homeButton = findViewById(R.id.home_button) as ImageButton
        homeButton.setOnClickListener(object : View.OnClickListener {
            override fun onClick(v: View?) {
                val intent = Intent(this@CommunityDisplay, HomeDisplay::class.java)
                startActivity(intent)
            }

        })

        fStorage = FirebaseStorage.getInstance()
        val qsRef = fStorage.getReference("Audio/Questions")

        fDatabase = FirebaseDatabase.getInstance()
        val postsRef = fDatabase.getReference("posts")

        var postRecyclerView : RecyclerView = findViewById(R.id.postRV)
        postRecyclerView.setLayoutManager(LinearLayoutManager(this))
        postRecyclerView.hasFixedSize()

        postsRef.addValueEventListener(object : ValueEventListener {
            override fun onDataChange(ds: DataSnapshot) {
                for (postSnap in ds.getChildren()) {
                    var post : Post = postSnap.getValue(Post::class.java)!!
                    postList.add(post)
                }

                postAdapter = PostAdapter(applicationContext, postList)
                postRecyclerView.setAdapter(postAdapter)
            }

            override fun onCancelled(p0: DatabaseError) {
                Log.d("DB Error", p0.toString())

            }

        })
    }
}

Мой почтовый адаптер:

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView


class PostAdapter(
    var mContext: Context,
    var mData: List<Post>
) :
    RecyclerView.Adapter<PostAdapter.MyViewHolder>() {
    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): MyViewHolder {
        val row: View =
            LayoutInflater.from(mContext).inflate(R.layout.row_post_item, parent, false)
        return MyViewHolder(row)
    }

    override fun onBindViewHolder(
        holder: MyViewHolder,
        position: Int
    ) {
        holder.tvTitle.text = mData[position].title
    }

    override fun getItemCount(): Int {
        return mData.size
    }

    inner class MyViewHolder(itemView: View) :
        RecyclerView.ViewHolder(itemView) {
        var tvTitle: TextView

        init {
            tvTitle = itemView.findViewById(R.id.row_post_title)

            itemView.setOnClickListener {
                val postDetailActivity =
                    Intent(mContext, QuestionDisplay::class.java)
                val position = adapterPosition
                postDetailActivity.putExtra("title", mData[position].title)
                postDetailActivity.putExtra("audioURL", mData[position].audioURL)
                postDetailActivity.putExtra("audioPath", mData[position].audioPath)

                mContext.startActivity(postDetailActivity)
            }
        }
    }

}

Мой код макета:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".CommunityDisplay">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_above="@+id/home_button">


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/PageTitle"
                android:text="Questions"
                android:layout_gravity="center"
                android:textSize="30sp"
                android:textAlignment="center"
                />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/postRV"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </LinearLayout>

        <ImageButton
            android:id="@+id/home_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="20dp"
            android:layout_marginBottom="20dp"
            android:background="@mipmap/home" />

    </RelativeLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

Элемент представления моего переработчика:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayoutaintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <TextView
        android:id="@+id/row_post_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayoutaintLayout>

Куда я иду не так?

Спасибо!

...