正在学习 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/