XML工具上下文错误

时间:2016-06-22 19:42:42

标签: java android xml layout

我目前正在学习大学模块的android开发,所以如果这是一个非常基本的错误,我很抱歉。我目前正在关注this tutorial,了解android java与普通java的区别等等。

XML文件activity_main 上,我收到以下错误:

  

无法解析符号$ {relativePackage}。$ {activityClass}   验证Android XML文件中的资源引用

我已经使用Google和StackOverflow搜索来查看可能的解决方案,我发现一些文章说明它可能是由于错误的XML格式化,这是我认为错误的地方。我也尝试运行该项目,它无法找到类文件R.我已经清理并重建了项目,但错误仍在继续。

Here is my code if you would like to take a look。虽然目前它与教程网站非常相似。

我的xml:

<RelativeLayout 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"
   tools:context="${relativePackage}.${activityClass}" >

    <LinearLayout
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_centerInParent="true"
       android:layout_marginLeft="20dp"
       android:layout_marginRight="20dp"
       android:gravity="center"
       android:orientation="vertical" >

        <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="@string/welcome"
           android:textSize="20dp" />

        <TextView
           android:id="@+id/name"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:padding="10dp"
           android:textColor="@color/lbl_name"
           android:textSize="24dp" />

        <TextView
           android:id="@+id/email"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:textSize="13dp" />

        <Button
           android:id="@+id/btnLogout"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:layout_marginTop="40dip"
           android:background="@color/btn_logut_bg"
           android:text="@string/btn_logout"
           android:textAllCaps="false"
           android:textColor="@color/white"
           android:textSize="15dp" />
    </LinearLayout>

</RelativeLayout>

任何帮助都很有用,谢谢

P.S我正在使用Android Studio

1 个答案:

答案 0 :(得分:1)

我的布局文件中有同样的错误,我找到了这个解释。 &#34;这是因为,在设计时应该没有添加任何组件。这是一个空活动。如果您想知道这个“$”符号混淆是什么,请放心,这只是配置文件允许运行时了解哪个Activity类与布局文件相关联的一种方式。&#34; 所以,你可以在那里添加你的课程或删除这一行。