Home>

With the following syntax
Android resource compilation failed
C: \ Users \ Administrator \ AndroidStudioProjects \ HelloWorld \ app \ src \ main \ res \ layout \ activity_main.xml: 15: AAPT: error: junk after document element.

C: \ Users \ Administrator \ AndroidStudioProjects \ HelloWorld \ app \ src \ main \ res \ layout \ activity_main.xml: AAPT: error: file failed to compile.

Error is displayed.
How can I fix it?

<? xml version = "1.0" encoding = "utf-8"?>

  <EditText
        android: id = "@ + id/etinput"
        android: layout_width = "match_parent"
        android: layout_height = "wrap_content"
        android: layout_marginBottom = "25dp"
        android: lauyout_marginTop = "5dp"
        android: background = "# ffffff"
        android: inputType = "text" />

  <ConstraintLayout
            android: layout_width = "match_parent"
            android: layout_height = "wrap_content"
            android: background = "# df7401"
            android: orientation = "horizontal">
      <CheckBox
            android: id = "@ + id/cbDrink"
            android: layout_width = "wrap_content"
            android: layout_heigt = "wrap_content"
            android: layout_marginRight = "25dp"
            android: background = "# ffffff"
            android: text = "@ string/cb_drink" />
      <CheckBox
            android: id = "@ + id/cbFood"
            android: layout_width = "wrap_content"
            android: layout_height = "wrap_content"
            android: text = "@ string/cb_food" />
  </ConstraintLayout>

  <Button
        android: id = "@ + id/btSave"
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "@ string/bt_save"
        tools: layout_editor_absoluteX = "-7dp"
        tools: layout_editor_absoluteY = "66dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
  • Answer # 1

    If you are using ConstraintLayout, you must constrain the child elements.
    You need to specify the following code for each View.

          app: layout_constraintStart_toStartOf = "parent"
            app: layout_constraintEnd_toEndOf = "parent"
            app: layout_constraintTop_toTopOf = "parent"
            app: layout_constraintBottom_toBottomOf = "parent"

    If the layout doesn't have to be particularly complicated, use ConstraintLayout.LinearLayoutIf you change to, you can change the layout to vertical or horizontal layout.

    Reference URL: https://techacademy.jp/magazine/4455

  • Answer # 2

    If it is not a typo, the last is "/>Because it isConstraintLayoutIsn't it because the tag of is closed?