java - XML 工具上下文错误

标签 java android xml layout

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

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

Cannot resolve symbol ${relativePackage}.${activityClass} Validates resource references inside Android XML Files

我使用 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

最佳答案

我的布局文件中有同样的错误,我找到了这个解释。 这是因为,设计时应该没有添加任何组件。它是一个空 Activity。如果你想知道这个“$”符号混淆是什么,放心,它只是配置文件的一种方式让运行时了解哪个 Activity 类与布局文件关联。” 因此,您可以在其中添加您的类或删除此行。

关于java - XML 工具上下文错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37976921/

相关文章:

java - JTable - 防止用户取消选择表中的所有元素

android - 在 travis yml 文件上配置 gradle.properties android.enableAapt=false

java - 将 JSONObject 格式化为 JSONArray

android - 使用 DialogInterface 的 onClick() 方法

安卓蓝牙 : Paired devices list

xml - 如何在 AngularJS 中处理 XML 服务?

javascript - 如何使用 Angular Directive(指令)获取隔离范围的更新值?

regex - 如何在正则表达式中包含双引号(“)

java - 由于缺少类路径引用,使用 Eclipse Mars 的 Ant 构建失败

java - Web 应用程序如何使用服务器发送的事件获取数据库更新并将更新传播到 Web 客户端?