java.lang.RuntimeException: 我该如何解决这个崩溃?是什么原因造成的?
java.lang.RuntimeException: How do I solve this crash? And what is causing this?
我的开发者控制台中显示了这个崩溃报告,但我完全不知道它是什么意思:
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3319)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3415)
at android.app.ActivityThread.access00 (ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1821)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:7406)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)
Caused by: android.view.InflateException:
at android.view.LayoutInflater.inflate (LayoutInflater.java:551)
at android.view.LayoutInflater.inflate (LayoutInflater.java:429)
at android.view.LayoutInflater.inflate (LayoutInflater.java:380)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView (AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView (AppCompatActivity.java:161)
at com.xxxxx.xxxxxxxxx.MainActivity.onCreate (MainActivity.java:91)
at android.app.Activity.performCreate (Activity.java:6904)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3266)
Caused by: android.view.InflateException:
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:810)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:855)
at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:810)
at android.view.LayoutInflater.inflate (LayoutInflater.java:527)
Caused by: android.content.res.Resources$NotFoundException:
at android.content.res.Resources.loadDrawableForCookie (Resources.java:4249)
at android.content.res.Resources.loadDrawable (Resources.java:4156)
at android.content.res.Resources.loadDrawable (Resources.java:4006)
at android.content.res.TypedArray.getDrawable (TypedArray.java:886)
at android.widget.ImageView.<init> (ImageView.java:157)
at android.widget.ImageView.<init> (ImageView.java:145)
at androidx.appcompat.widget.AppCompatImageView.<init> (AppCompatImageView.java:72)
at androidx.appcompat.widget.AppCompatImageView.<init> (AppCompatImageView.java:68)
at androidx.appcompat.app.AppCompatViewInflater.createImageView (AppCompatViewInflater.java:187)
at androidx.appcompat.app.AppCompatViewInflater.createView (AppCompatViewInflater.java:107)
at androidx.appcompat.app.AppCompatDelegateImpl.createView (AppCompatDelegateImpl.java:1407)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView (AppCompatDelegateImpl.java:1457)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:758)
第 91 行代码如下:
setContentView(R.layout.activity_main);
所以我认为它必须对 XML 文件做些什么。
这是 activity_main.xml 文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:id="@+id/mainview">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/main_color"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="My App" />
<ImageView
android:id="@+id/search_ico"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:src="@drawable/ic_search_white_24dp"
app:layout_constraintBottom_toBottomOf="@+id/toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/drawerLayout">
<com.google.android.material.navigation.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="@+id/navigationView"
app:itemTextColor="@color/black"
app:menu="@menu/drawermenu"
/>
</androidx.drawerlayout.widget.DrawerLayout>
</LinearLayout>
我添加了带有上次更新的搜索图标和约束布局的 ImageView,在添加之前一切正常。
Android 版本 6 的用户无法打开该应用程序。
请帮我解决这个问题,谢谢!
除了 drawable-v24
之外,您还必须在项目 res
目录的 drawable
文件夹中添加 ic_search_white_24dp
以支持低于 API 级别的设备24.
我的开发者控制台中显示了这个崩溃报告,但我完全不知道它是什么意思:
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3319)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3415)
at android.app.ActivityThread.access00 (ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1821)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:7406)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)
Caused by: android.view.InflateException:
at android.view.LayoutInflater.inflate (LayoutInflater.java:551)
at android.view.LayoutInflater.inflate (LayoutInflater.java:429)
at android.view.LayoutInflater.inflate (LayoutInflater.java:380)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView (AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView (AppCompatActivity.java:161)
at com.xxxxx.xxxxxxxxx.MainActivity.onCreate (MainActivity.java:91)
at android.app.Activity.performCreate (Activity.java:6904)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3266)
Caused by: android.view.InflateException:
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:810)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:855)
at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:810)
at android.view.LayoutInflater.inflate (LayoutInflater.java:527)
Caused by: android.content.res.Resources$NotFoundException:
at android.content.res.Resources.loadDrawableForCookie (Resources.java:4249)
at android.content.res.Resources.loadDrawable (Resources.java:4156)
at android.content.res.Resources.loadDrawable (Resources.java:4006)
at android.content.res.TypedArray.getDrawable (TypedArray.java:886)
at android.widget.ImageView.<init> (ImageView.java:157)
at android.widget.ImageView.<init> (ImageView.java:145)
at androidx.appcompat.widget.AppCompatImageView.<init> (AppCompatImageView.java:72)
at androidx.appcompat.widget.AppCompatImageView.<init> (AppCompatImageView.java:68)
at androidx.appcompat.app.AppCompatViewInflater.createImageView (AppCompatViewInflater.java:187)
at androidx.appcompat.app.AppCompatViewInflater.createView (AppCompatViewInflater.java:107)
at androidx.appcompat.app.AppCompatDelegateImpl.createView (AppCompatDelegateImpl.java:1407)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView (AppCompatDelegateImpl.java:1457)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:758)
第 91 行代码如下:
setContentView(R.layout.activity_main);
所以我认为它必须对 XML 文件做些什么。 这是 activity_main.xml 文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:id="@+id/mainview">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/main_color"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="My App" />
<ImageView
android:id="@+id/search_ico"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:src="@drawable/ic_search_white_24dp"
app:layout_constraintBottom_toBottomOf="@+id/toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/drawerLayout">
<com.google.android.material.navigation.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="@+id/navigationView"
app:itemTextColor="@color/black"
app:menu="@menu/drawermenu"
/>
</androidx.drawerlayout.widget.DrawerLayout>
</LinearLayout>
我添加了带有上次更新的搜索图标和约束布局的 ImageView,在添加之前一切正常。 Android 版本 6 的用户无法打开该应用程序。 请帮我解决这个问题,谢谢!
除了 drawable-v24
之外,您还必须在项目 res
目录的 drawable
文件夹中添加 ic_search_white_24dp
以支持低于 API 级别的设备24.