java - Android XML 中的多个错误

标签 java android xml

正在学习 Android,我的 XML 文件中出现以下错误:

  • 解析 XML 时出错:文档元素后出现垃圾;和
  • 属性缺少命名空间前缀。

任何帮助将不胜感激:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="25dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" />

    <EditText
        android:id="@+id/etCommands"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android.password="true"
        android:hint="Type a Command" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="100" >

        <Button
            android:id="@+id/bResults"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="20"
            android:text="Try Command" />

        <ToggleButton
            android:id="@+id/tbPassword"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_weight="80"
            android:checked="true"
            android:paddingBottom="10dp"
            android:text="ToggleButton" />

    </LinearLayout>

    <TextView
        android:id="@+id/tvResults"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Invalid" />

</LinearLayout>

最佳答案

您的部分问题在本节中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="25dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />

您正在使用 /> 关闭该元素

删除/

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="25dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

这样直到最后它才关闭。您将在文档的其余部分之前关闭根元素。

并对编辑文本进行一点更改:

 <EditText
        android:id="@+id/etCommands"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        <!-- change below the . to : -->
        android:password="true"
        android:hint="Type a Command" />

关于java - Android XML 中的多个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24165853/

相关文章:

android - 关于将 textViews 与其底部边缘直线对齐的问题

java - f :convertDateTime support for Java8 LocalDate/LocalDateTime?

java - 如何在 Java 应用程序中使用最小库来检测音频源的节拍?

android - Android 中的 Fitbit 账户集成

java - Android Studio 在 i7 处理器上使用 100% CPU 进行项目重建

XML 文件中的 Java 替换

java - 更新 firebase 实时数据库中键的值时出现问题

java - 效率 ?这些代码之间有什么区别吗?

android - 是否可以让内置的谷歌地图显示地址

java - 如何使用 XML Config 通过 MappingJackson2HttpMessageConverter 设置自定义属性命名策略?