Java 二进制XML文件行#15:未能解析索引1处的属性:TypedValue{t=0x2/d=0x7f030003 a=-1}

Java 二进制XML文件行#15:未能解析索引1处的属性:TypedValue{t=0x2/d=0x7f030003 a=-1},java,android,android-studio,android-layout,Java,Android,Android Studio,Android Layout,我正在Android Studio上构建一个计算器应用程序。当我在Android Pie设备上运行应用程序时,发生了以下致命错误。由于我是Android开发的新手,我没有在错误发生时立即执行,java文件中没有包含计算器的主要功能 [日志] java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.calculator/com.example.calculator.MainActivity}: a

我正在Android Studio上构建一个计算器应用程序。当我在Android Pie设备上运行应用程序时,发生了以下致命错误。由于我是Android开发的新手,我没有在错误发生时立即执行,java文件中没有包含计算器的主要功能

[日志]

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.calculator/com.example.calculator.MainActivity}: android.view.InflateException: Binary XML file line #15: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3037)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6863)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: android.view.InflateException: Binary XML file line #15: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}
 Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}
    at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:794)
    at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:7767)
    at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7958)
    at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1997)
    at android.support.design.widget.AppBarLayout$LayoutParams.<init>(AppBarLayout.java:743)
    at android.support.design.widget.AppBarLayout.generateLayoutParams(AppBarLayout.java:366)
    at android.support.design.widget.AppBarLayout.generateLayoutParams(AppBarLayout.java:110)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
    at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
    at com.example.calculator.MainActivity.onCreate(MainActivity.java:26)
    at android.app.Activity.performCreate(Activity.java:7149)
    at android.app.Activity.performCreate(Activity.java:7140)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1288)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3017)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6863)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
相应的activity_main.xml文件中的内容是

    <?xml version="1.0" encoding="utf-8"?>
<layout>
    <android.support.design.widget.CoordinatorLayout 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"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />

    </android.support.design.widget.CoordinatorLayout>
</layout>

最后,content_main.xml中的内容是

    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:importantForAutofill="no"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    tools:showIn="@layout/activity_main">

    <Button
        android:id="@+id/bt_plus"
        style="@style/Widget.MaterialComponents.Button.TextButton"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_marginStart="21dp"
        android:layout_marginTop="57dp"
        android:fontFamily="monospace"
        android:text="@string/button_plus"
        android:textSize="30sp"
        android:typeface="normal"
        app:layout_constraintEnd_toStartOf="@+id/bt_minus"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tb_valueA" />

    <Button
        android:id="@+id/bt_minus"
        style="@style/Widget.MaterialComponents.Button.TextButton"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_marginStart="24dp"
        android:layout_marginTop="57dp"
        android:fontFamily="monospace"
        android:text="@string/button_minus"
        android:textSize="30sp"
        android:typeface="normal"
        app:layout_constraintEnd_toStartOf="@+id/bt_multiply"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/bt_plus"
        app:layout_constraintTop_toBottomOf="@+id/tb_valueA" />

    <Button
        android:id="@+id/bt_multiply"
        style="@style/Widget.MaterialComponents.Button.TextButton"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_marginStart="24dp"
        android:layout_marginTop="57dp"
        android:fontFamily="monospace"
        android:text="@string/button_multiply"
        android:textSize="30sp"
        android:typeface="normal"
        app:layout_constraintEnd_toStartOf="@+id/bt_divide"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/bt_minus"
        app:layout_constraintTop_toBottomOf="@+id/tb_valueB" />

    <Button
        android:id="@+id/bt_divide"
        style="@style/Widget.MaterialComponents.Button.TextButton"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_marginStart="20dp"
        android:layout_marginTop="57dp"
        android:layout_marginEnd="16dp"
        android:fontFamily="monospace"
        android:text="@string/button_divide"
        android:textSize="30sp"
        android:typeface="normal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/bt_multiply"
        app:layout_constraintTop_toBottomOf="@+id/tb_valueB" />

    <EditText
        android:id="@+id/tb_valueA"
        android:layout_width="0dp"
        android:layout_height="44dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="158dp"
        android:layout_marginEnd="12dp"
        android:ems="10"
        android:fontFamily="serif-monospace"
        android:hint="@string/valueA"
        android:importantForAutofill="no"
        android:inputType="numberDecimal"
        android:text="@string/valueA"
        android:textColor="@android:color/holo_orange_dark"
        android:textSize="24sp"
        android:typeface="monospace"
        app:layout_constraintEnd_toStartOf="@+id/tb_valueB"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/tb_valueB"
        android:layout_width="0dp"
        android:layout_height="44dp"
        android:layout_marginTop="158dp"
        android:layout_marginEnd="16dp"
        android:ems="10"
        android:fontFamily="serif-monospace"
        android:hint="@string/valueB"
        android:importantForAutofill="no"
        android:inputType="numberDecimal"
        android:text="@string/valueB"
        android:textColor="@android:color/holo_red_dark"
        android:textSize="24sp"
        android:typeface="monospace"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/tb_valueA"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv_result"
        android:layout_width="155dp"
        android:layout_height="50dp"
        android:layout_marginStart="206dp"
        android:layout_marginTop="68dp"
        android:layout_marginEnd="23dp"
        android:layout_marginBottom="132dp"
        android:fontFamily="serif-monospace"
        android:text="@string/result"
        android:textSize="30sp"
        android:typeface="monospace"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.222"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/bt_multiply"
        app:layout_constraintVertical_bias="0.962" />

</android.support.constraint.ConstraintLayout>

我不知道这是否有帮助,但你应该在styles.xml文件中检查你的应用程序主题。如果你改变了它,你就把它改成了一种与你的活动不兼容的形式,从我看来,这似乎是一种“基本活动”的形式

对于初学者,尝试将其更改为从Theme.AppCompat派生的。另外,也不要忘记定义它并在android清单中的活动中使用它

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

假的
真的

至于一个修复,让你保持你的主题和解决问题。我会就此与您联系。

我不知道这是否有帮助,但您应该在styles.xml文件中检查应用程序主题。如果你改变了它,你就把它改成了一种与你的活动不兼容的形式,从我看来,这似乎是一种“基本活动”的形式

对于初学者,尝试将其更改为从Theme.AppCompat派生的。另外,也不要忘记定义它并在android清单中的活动中使用它

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

假的
真的

至于一个修复,让你保持你的主题和解决问题。我会就此回复您。

您的布局文件找不到?attr/actionBarSize

要获取AppCompat中的操作栏大小,请执行以下操作:

?android:attr/actionBarSize
也可以手动设置:

56dp (default)
48dp (landscape)
64dp (sw600dp; i.e. tablet)

布局文件找不到?attr/actionBarSize

要获取AppCompat中的操作栏大小,请执行以下操作:

?android:attr/actionBarSize
也可以手动设置:

56dp (default)
48dp (landscape)
64dp (sw600dp; i.e. tablet)

content_main.xml中的第15行显示问题。尝试将android:layout\u width=“0dp”更改为android:layout\u width=“100dp”//something,看看问题是否仍然存在。问题仍然带有相同的错误消息。content\u main.xml中的第15行显示问题。尝试将android:layout\u width=“0dp”更改为android:layout\u width=“100dp”//something,看看问题是否仍然存在。问题仍然带有相同的错误消息。