gpt4 book ai didi

无法识别 Android 布局 ID

转载 作者:行者123 更新时间:2023-11-30 05:02:23 24 4
gpt4 key购买 nike

我试图让 Android Studio 识别我的 layout.xml 文件中各种 View 的 ID 等。当我在 xml 中输入代码时,一切似乎都正常,但是当我今天重新访问我的代码时,布局文件中的 id 显示为红色,显示“无法解析符号”。

当我尝试访问 View 时(例如使用“view.findViewById(R.id.splo)”),它说它无法解析符号(在本例中为“splo”)。

我没有做任何激进的事情,例如这是我在布局 xml 中定义 splo 的方式:

        <TextView android:id="@+id/splo" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="" />

进行一些挖掘,我发现我没有 res/values/id.xml 文件 - 进一步查看我在 app/build/generated/source 下没有任何东西,所以也没有 R.java 文件.

我查看了一些人的帮助请求 - 一个与我的请求非常相似 ("cannot resolve symbol R" in Android Studio),但提供的解决方案没有帮助。

我已经完成了多次使缓存无效并重新启动,无论是否使用 Build->clean 项目,但没有任何效果,而且 ID 仍然无法识别。谁能帮忙?

最佳答案

在构建应用程序时,包名称中可能存在潜在错误。

Since you mentioned, you already tried rebuilding and cleaning the project, we won't waste time doing that again!


我现在要你做的是:

  1. 打开您的 AndroidMainfest.xml 文件
  2. 滚动到顶部并检查名称是否正确
  3. 如果正确,则转到 ma​​nifest 中的 Activity 定义并检查:
    • 如果这些行中的名称[android:name="YOUR_PACKAGE_NAME.YOUR_ACTIVITY_NAME"]是正确分配
    • 如果您看到以上行的格式为 [android:name=".YOUR_ACTIVITY_NAME]",请将其添加为上述格式点前的包名
    • 现在清理重建您的项目。

The problem should be solved and if not my request is that please Upload your AndroidManifest.xml file and your package information so that I can have a better look at the issue

关于无法识别 Android 布局 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58034021/

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