我正在为Firebase实时数据库设置一个应用程序。为此,我想在垂直布局中给出数据。问题是当我添加LinearLayoutManager时应用程序停止了。
这是我遵循的教程:https://www.youtube.com/watch?v=71H9-MRXYOE
我已经尝试以不同的方式添加LinearLayoutManager,但是没有一个起作用
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this,
RecyclerView.VERTICAL, false));
recyclerView.setAdapter(adapter);
}
我对使用android编程真的很陌生,对错误代码了解不多。
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
at void androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, androidx.core.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)
at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)
I/art: at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
at void com.example.firebasetest.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:34)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6679)
at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1118)
at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2618)
at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2726)
at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1477)
at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
at void android.os.Looper.loop() (Looper.java:154)
at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6119)
at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:886)
at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:776)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.example.firebasetest-2/base.apk", zip file "/data/app/com.example.firebasetest-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.firebasetest-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.firebasetest-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.firebasetest-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.firebasetest-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.firebasetest-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.firebasetest-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.firebasetest-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.firebasetest-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.firebasetest-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.firebasetest-2/split_lib_slice_9_apk.apk"],na
at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
at void androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, androidx.core.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)
at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)
at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
at void com.example.firebasetest.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:34)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6679)
at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1118)
at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2618)
at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2726)
at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1477)
at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
at void android.os.Looper.loop() (Looper.java:154)
at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6119)
at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:886)
at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:776)
I/ViewConfigCompat: Could not find method getScaledScrollFactor() on ViewConfiguration
这是我的布局
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/edt_title"
android:hint="Title"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/edt_content"
android:hint="Content"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btn_post"
android:text="POST"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"></androidx.recyclerview.widget.RecyclerView>
</LinearLayout>```
答案 0 :(得分:0)
1]垂直滚动RecyclerView
可以通过以下方式实现:-
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(linearLayoutManager);
2] logcat
中的错误显示如下:-
java.lang.ClassNotFoundException:未找到类 路径上的“ android.view.View $ OnUnhandledKeyEventListener”: DexPathList [[zip文件“ /data/app/com.example.firebasetest-2/base.apk”, 压缩文件 “ /data/app/com.example.firebasetest-2/split_lib_dependencies_apk.apk”, 压缩文件 “ /data/app/com.example.firebasetest-2/split_lib_slice_0_apk.apk”,邮政编码 文件“ /data/app/com.example.firebasetest-2/split_lib_slice_1_apk.apk”, 压缩文件 “ /data/app/com.example.firebasetest-2/split_lib_slice_2_apk.apk”,邮政编码 文件“ /data/app/com.example.firebasetest-2/split_lib_slice_3_apk.apk”, 压缩文件 “ /data/app/com.example.firebasetest-2/split_lib_slice_4_apk.apk”,邮政编码 文件“ /data/app/com.example.firebasetest-2/split_lib_slice_5_apk.apk”, 压缩文件 “ /data/app/com.example.firebasetest-2/split_lib_slice_6_apk.apk”,邮政编码 文件“ /data/app/com.example.firebasetest-2/split_lib_slice_7_apk.apk”, 压缩文件 “ /data/app/com.example.firebasetest-2/split_lib_slice_8_apk.apk”,邮政编码 文件 “ /data/app/com.example.firebasetest-2/split_lib_slice_9_apk.apk”],na
基本上可以解决的问题(主要集中在与Fire base相关的依赖项上)
最后
3]清理项目,重建并运行。
答案 1 :(得分:0)
您的问题不在LayoutManager中。问题在于此错误消息:
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
这已经被回答了看这个链接 https://stackoverflow.com/a/45191408/11555781
答案 2 :(得分:0)
当我将图库切换到RecyclerView时,这个问题对我来说尤为突出。 我可以通过将以下依赖项添加到我的build.gradle文件中来解决该问题:
implementation 'androidx.core:core:1.5.0-alpha01'