gpt4 book ai didi

java - 在模拟器中打开时 Android 代码崩溃

转载 作者:数据小太阳 更新时间:2023-10-29 02:52:43 24 4
gpt4 key购买 nike

我是 java 的新手,但出于某种原因,我正在尝试创建一个应用程序该应用程序在 android studio 中正确构建,但是,当尝试在模拟器中打开时,它崩溃了。 This是我的完整代码

是应用程序的 zip,我猜,主要错误是

final View rootView = inflater.inflate(R.layout.fragment_sun, container, false); 

Logcat:错误

2019-07-25 10:42:48.002 5383-5383/com.example.phocast E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.phocast, PID: 5383
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.v7.widget.RecyclerView
Caused by: android.view.InflateException: Binary XML file line #2: 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.phocast-j1KYRRVBUGO2ddQzmNBB8w==/base.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_resources_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.example.phocast.ui.main.SunFragment.onCreateView(SunFragment.java:69)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)

SunFragment.java 代码的第 69 行。

我不明白 XML 中出了什么问题。

对应的XML为:

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" />

有人可以检查一下吗?

build.gradel

apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.phocast"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation'com.google.android.gms:play-services-places:17.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'org.shredzone.commons:commons-suncalc:2.6'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
}

最佳答案

使用

androidx.recyclerview.widget.RecyclerView

fragment_sun.xml 而不是

android.support.v7.widget.RecyclerView

因为在 build.gradle 中,依赖项是 androidx.recyclerview:recyclerview:1.0.0 但在 SunFragment 中,RecyclerView 是从 导入的>androidx

关于java - 在模拟器中打开时 Android 代码崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57194683/

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