android.view.InflateException: Binary XML 文件行 #37: Binary XM


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:background="@drawable/background"
android:layoutDirection="ltr"
android:paddingBottom="25sp"
android:paddingLeft="5sp"
android:paddingRight="5sp"
android:paddingTop="25sp"
tools:context=".MainActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="25dp"
android:src="@drawable/mainlogo"
android:id="@+id/ClickHereToEnter"
android:layout_marginBottom="25dp"
android:gravity="center">
</ImageView>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/lunch"
android:layout_marginBottom="15dp"
android:textColor="#90A4AE"
android:textStyle="bold"
android:textSize="30sp"
android:gravity="center"/>
</LinearLayout>

这个错误出现在我面前,我不知道为什么?? 并且无法解决它的任何帮助,请? 运行应用程序时,我会出现此错误,并在第 17 行的 Java 页面中检测到错误 (setContentView(R.layout.activity_main((!!那么谁能帮我?

你必须添加到你的XML文件中,希望对你有所帮助。

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:titleTextColor="@android:color/black" />

我认为您可能正在使用支持库的工具栏并具有androidx的依赖项。检查您在build.gradle中的依赖项是androidX还是支持库,并相应地在xml布局文件中使用该工具栏。