初学者Android Studio:意外的令牌?

时间:2018-04-08 04:30:15

标签: android

我正在学习如何在Android Studio中创建一些基本应用。现在我正在努力学习" Echoing"的概念。我在给我的教授代码时遇到了问题,这里是在activity_main.xml中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
        <EditText android:id="@+id/edit_message"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:hint="@string/edit_message" />
        <Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/button_send" />
</LinearLayout>

这给了我多个错误,其中大多数都说出了意外的令牌,或者错误:(3)解析XML时出错:格式不正确(无效令牌)。这个基本的xml出了什么问题?

1 个答案:

答案 0 :(得分:2)

您使用同步gradle时遇到问题,并且您发布的XML没有问题

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
        <EditText android:id="@+id/edit_message"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:hint="@string/edit_message" />
        <Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/button_send" />
</LinearLayout>

以上/您的XML代码适用于任何人。同步Gradle并再次尝试运行该应用。如果您仍面临同样的问题,请创建新项目并将上述/您的XML和Java代码放在该新项目中