“无法解析符号"使用 android:id="@+android:id/my_id" 时出错; [英] "Cannot Resolve Symbol" Error when using android:id="@+android:id/my_id"
问题描述
当我将 android:id/background 添加到命名空间时,Lint 抱怨它无法解析符号",即使我请求添加它而不是调用它.该代码按编写方式工作,但错误仍然存在.当我将 <item android:id="@+android:id/background" 更改为 <item android:id="@+id/background"
时,应用程序停止工作(另一个呼叫中断).我的问题是:为什么 Lint 无法识别我将 android:id/background 添加到命名空间,即使对它的调用运行良好?有没有更好的方法可以给这个项目一个不会让 Lint 抛出错误的 id?
When I am adding android:id/background to the namespace, Lint complains that it "Cannot Resolve Symbol" even though I am requesting to add it rather than call it. The code works as written, but the error persists. When I change <item android:id="@+android:id/background" to <item android:id="@+id/background"
, the application stops working (another call breaks). My question is: why does Lint not recognize me adding android:id/background to the namespace even though a call to it functions well? Is there some better way to give this item an id that won't have Lint throw an error?
下面层列表中项目的所有三个命名空间定义都抛出一个 lint 错误:
All three of the namespace definitions for the items in the layer-list below throw a lint error:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+android:id/background"
android:drawable="@drawable/custom_ratingbar_empty" />
<item android:id="@+android:id/secondaryProgress"
android:drawable="@drawable/custom_ratingbar_empty" />
<item android:id="@+android:id/progress"
android:drawable="@drawable/custom_ratingbar_filled" />
</layer-list>
我找到了 this 并尝试按照建议运行 build->clean没有成功.
I found this and tried running build->clean as suggested with no success.
推荐答案
如果您要创建自己的 ID:
If you are creating your own id:
"@+id/your_new_id"
如果您正在访问您已经创建的 ID
if you are accessing your already created id
"@id/your_old_id"
如果您尝试访问 Android 系统创建的 ID
if you are trying to access Android's system created id
"@android:id/system_id"
您可以看到不同之处,如果您要创建自己的 ID,则必须添加 +
.由于您正在访问系统 ID,因此您不必添加 +
you can see the difference, if you are creating your own id then you have to add +
. Since you are accessing system ID so you don't have to add +
这篇关于“无法解析符号"使用 android:id="@+android:id/my_id" 时出错;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!