gpt4 book ai didi

java - XML 工具上下文错误

转载 作者:行者123 更新时间:2023-12-01 09:46:27 25 4
gpt4 key购买 nike

我目前正在为大学模块学习 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com