gpt4 book ai didi

java - 添加 RecyclerView Layoutmanager 时我的应用程序停止了

转载 作者:行者123 更新时间:2023-12-02 04:43:04 25 4
gpt4 key购买 nike

我正在为 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>```

最佳答案

  • 也许这会有所帮助

1]垂直滚动RecyclerView可以通过以下方式实现:-

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(linearLayoutManager);

2] logcat 中的错误显示如下:-

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

基本上可以通过以下方式解决(主要关注Firebase相关依赖)

  • 清理项目依赖项
  • 如果需要,请将所有依赖项更新为最新版本。

最后

3]清理您的项目,重建并运行。

关于java - 添加 RecyclerView Layoutmanager 时我的应用程序停止了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56505383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com