android - 错误膨胀类 ImageButton 停止应用程序启动

标签 android android-xml android-inflate

我的应用程序无法启动,因为 Error inflating class ImageButton,因此手机显示“应用程序已停止”等。 我正在使用 firebase 测试实验室来调试问题

错误发生在三星设备上,特别是 A20、s7 Edge、s7(用 firebase 测试同样的问题)

我是 android 的新手,已经尝试了谷歌的许多解决方案,但到目前为止都没有成功

这里是firebase的错误报告

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartpractice.smartpracticesmartapp/com.smartpractice.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #117: Binary XML file line #117: Error inflating class ImageButton
     FATAL EXCEPTION: main
Process: com.smartpractice.smartpracticesmartapp, PID: 26921
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartpractice.smartpracticesmartapp/com.smartpractice.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #117: Binary XML file line #117: Error inflating class ImageButton
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
    at android.app.ActivityThread.access$1100(ActivityThread.java:221)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7224)
    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: Binary XML file line #117: Binary XML file line #117: Error inflating class ImageButton
    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:469)
    at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at com.smartpractice.myapplication.MainActivity.onCreate(MainActivity.java:14)
    at android.app.Activity.performCreate(Activity.java:6876)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
    ... 9 more
Caused by: android.view.InflateException: Binary XML file line #117: Error inflating class ImageButton
    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)
    ... 17 more
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070089
    at android.content.res.Resources.getValue(Resources.java:2558)
    at androidx.appcompat.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:331)
    at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198)
    at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
    at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:102)
    at androidx.appcompat.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:59)
    at androidx.appcompat.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:79)
    at androidx.appcompat.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:69)
    at androidx.appcompat.app.AppCompatViewInflater.createImageButton(AppCompatViewInflater.java:202)
    at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:122)
    at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
    at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:758)

这是 XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relativeLayout4"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/ic_launcher_background"
    tools:context=".MainActivity">

    <com.google.android.flexbox.FlexboxLayout
        android:id="@+id/flexboxLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        app:alignContent="stretch"
        app:alignItems="stretch"
        app:flexWrap="wrap"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.863"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline7">


        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:fontFamily="@font/nunito"
            android:gravity="center_horizontal"
            android:text="@string/welcome_to_smartpractice"
            android:textSize="24sp"
            app:fontFamily="@font/nunito"
            app:layout_alignSelf="baseline"
            tools:layout_editor_absoluteY="100dp"
            tools:targetApi="jelly_bean" />

        <TextView
            android:id="@+id/textView7"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimaryDark"
            android:gravity="center_horizontal|fill_vertical"
            android:text="@string/docsharesmart"
            android:textColor="@color/ic_launcher_background"
            app:layout_alignSelf="flex_end"
            tools:layout_editor_absoluteY="16dp" />

    </com.google.android.flexbox.FlexboxLayout>

    <com.google.android.flexbox.FlexboxLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="4dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        app:alignContent="center"
        app:alignItems="stretch"
        app:flexDirection="row"
        app:flexWrap="nowrap"
        app:justifyContent="space_between"
        app:layout_constraintBottom_toTopOf="@+id/guideline7"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/logo1"
            app:layout_alignSelf="center"
            app:srcCompat="@drawable/smartpractice_logo_02"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="-46dp" />

        <ImageButton
            android:id="@+id/LoginScreen"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@null"
            android:contentDescription="@string/loginscreen"
            app:layout_alignSelf="center"
            app:layout_wrapBefore="false"
            app:srcCompat="@drawable/ic_more_vert_black_24dp"
            tools:layout_editor_absoluteX="248dp"
            tools:layout_editor_absoluteY="134dp" />


    </com.google.android.flexbox.FlexboxLayout>

    <com.google.android.flexbox.FlexboxLayout
        android:id="@+id/flexboxLayout2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        app:alignContent="stretch"
        app:alignItems="stretch"
        app:flexWrap="wrap"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/flexboxLayout"
        app:layout_constraintVertical_bias="0.146">

这是错误的第 117 行

        <ImageButton
            android:id="@+id/UploadButton"
            android:layout_width="300dp"
            android:layout_height="209dp"
            android:background="@android:color/transparent"
            app:layout_constraintTop_toBottomOf="@+id/flexboxLayout"
            app:srcCompat="@drawable/upload_files_upload"
            android:contentDescription="@string/todo" />


    </com.google.android.flexbox.FlexboxLayout>


    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="185dp" />


</androidx.constraintlayout.widget.ConstraintLayout>

最佳答案

这意味着在 drawble 文件夹中找不到 upload_files_upload,这可能是一种情况,您的文件可能存在于 drawable-24 而不是 drawble 文件夹,这样的话还是会出现这个问题。重点是您的文件必须在所有drawble 文件夹中。

关于android - 错误膨胀类 ImageButton 停止应用程序启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58281395/

相关文章:

android - 可绘制图像缩放

android - 如何更改 UI 小部件尺寸从 iPhone 4 Retina 到 Android

android - 我可以在自定义 View 中访问 xml 定义的 subview 的最早时间点是什么

android - 从 ActionBar 获取项目 View

Android Mupdf : PDF viewer silenty crashed due to low memory after 13 pages

android - 如何从 fragment 中开始 Activity ?

android - 改变 RadioButton 的背景覆盖单选按钮 android 上的文本

android - 创建双行项目布局后无用的属性

android - Nexus S 和 Galaxy Nexus 的布局和绘图

Android:在同一 Activity 中更改布局