Я пробую recyleview в Android впервые.Я следовал этому уроку https://developer.android.com/guide/topics/ui/layout/recyclerview
Приложение свежее и содержит только одно действие.Цель на данный момент - просто отобразить список строк, используя recyleview.Приложение компилируется, но если я запускаю его (на виртуальном устройстве api 26), оно вылетает с ошибкой.
Я попытался запустить с API lvl 26 и 28. Я также попытался изменить версию поддержкиlibarys, но это полностью разрушило мое первое приложение ...
Я прочитал множество результатов Google, которые касаются проблемы.Но все они, кажется, имеют разные очень специфические причины.Которые я не смог применить к своей проблеме.
Мои зависимости:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.android.support:recyclerview-v7:28.0.0'
}
Моя активность:
package com.example.myfirstapp
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
class MainActivity : AppCompatActivity() {
private lateinit var recyclerView: RecyclerView
private lateinit var viewAdapter: RecyclerView.Adapter<*>
private lateinit var viewManager: RecyclerView.LayoutManager
private val myArray = arrayOf("Hans","Klaus")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
viewManager = LinearLayoutManager(this)
viewAdapter = MyAdapter(myArray)
recyclerView = findViewById<RecyclerView>(R.id.my_recycler_view).apply {
setHasFixedSize(true)
layoutManager = viewManager
adapter = viewAdapter
}
}
}
class MyAdapter(private val myDataset: Array<String>) :
RecyclerView.Adapter<MyAdapter.MyViewHolder>() {
class MyViewHolder(val textView: TextView) : RecyclerView.ViewHolder(textView)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyAdapter.MyViewHolder {
val textView = LayoutInflater.from(parent.context)
.inflate(R.layout.my_text_view, parent, false) as TextView
return MyViewHolder(textView)
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
holder.textView.text = myDataset[position]
}
override fun getItemCount() = myDataset.size
}
Вызванная часть ошибки:
Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class android.support.v7.widget.RecyclerView
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.v7.widget.RecyclerView
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.RecyclerView" on path: DexPathList[[zip file "/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/base.apk", zip file "/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/split_lib_resources_apk.apk", zip file "/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.myfirstapp-O0jrBUQE1V6V1rEdCmyGrg==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)