在代码中放置特定imageView时遇到android.view.inflateException

z9smfwbn  于 2022-12-02  发布在  Android
关注(0)|答案(1)|浏览(112)

我已经设置了一个图像资产图标只是为了用户界面的需要,但它显示错误。我检查了图像是否正确,它是正确的,大小为1 KB。我无法找出什么问题在这里。这里是我的错误图像代码:

<ImageButton
    android:id="@+id/arrow_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/_5sdp"
    android:src="@drawable/ic_baseline_expand_more_24"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.802"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintVertical_bias="0.0" />

以下是logcat中显示的完整错误日志:

FATAL EXCEPTION: main
Process: com.gtappdevelopers.gfgroomdatabase, PID: 24472
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gtappdevelopers.gfgroomdatabase/com.gtappdevelopers.gfgroomdatabase.NewCourseActivity}: android.view.InflateException: Binary XML file line #421: Binary XML file line #421: Error inflating class ImageButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
Caused by: android.view.InflateException: Binary XML file line #421: Binary XML file line #421: Error inflating class ImageButton
at android.view.LayoutInflater.inflate(LayoutInflater.java:543)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.gtappdevelopers.gfgroomdatabase.NewCourseActivity.onCreate(NewCourseActivity.java:117)
at android.app.Activity.performCreate(Activity.java:6303)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483) 
at android.app.ActivityThread.access$900(ActivityThread.java:153) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5441) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628) 
Caused by: android.view.InflateException: Binary XML file line #421: Error inflating class ImageButton
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:786)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:839)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699) 
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195) 
at com.gtappdevelopers.gfgroomdatabase.NewCourseActivity.onCreate(NewCourseActivity.java:117) 
at android.app.Activity.performCreate(Activity.java:6303) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483) 
at android.app.ActivityThread.access$900(ActivityThread.java:153) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5441) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628) 
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f08006c
at android.content.res.Resources.getValue(Resources.java:1369)
at android.content.res.MiuiResources.getValue(MiuiResources.java:145)
at androidx.appcompat.widget.ResourceManagerInternal.loadDrawableFromDelegates(ResourceManagerInternal.java:255)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:142)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:135)
at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:104)
at androidx.appcompat.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:63)
at androidx.appcompat.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:83)
at androidx.appcompat.widget.AppCompatImageButton.<init>(AppCompatImageButton.ja

我期待应用程序工作正常,但它显示了这个错误。

ifsvaxew

ifsvaxew1#

如果查看堆栈跟踪的底部,将看到以下行:
导致异常的原因:资源识别码#0x7f08006c
未找到资源ID为#0x7f08006c的资源。由于ID为7f的包,因此这是您创建的资源。(Android资源包代码为0x01。)
您已经正确地将问题的来源识别为 ImageButton,因为我们在前面的跟踪中看到了以下内容:
java.lang.RuntimeException:无法启动活动组件信息{com.gtappdevelopers.gfgroomdatabase/com.gtappdevelopers.gfgroomdatabase.NewCourseActivity}:android.view.InflateException:二进制XML文件第421行:二进制XML文件第421行:膨胀类ImageButton时出错
因此,看起来缺少可绘制对象。您可以从Resources#getResourceName(int)中获取可绘制对象的名称,尽管假定您已经识别了正确的 ImageButton,它无疑将是drawable/ic_baseline_expand_more_24
检查您的基本drawable文件夹,以确保drawable已在那里定义为后备。

相关问题