Android findViewById()为getChildAt()找到的视图返回null

Android findViewById()为getChildAt()找到的视图返回null,android,android-layout,android-source,findviewbyid,Android,Android Layout,Android Source,Findviewbyid,我正在对AOSP SystemUI应用程序进行一些修改,并且在尝试在任意设备上运行它时遇到了一个非常特殊的问题:findViewById()返回null,而在其子项中导航则显示它确实存在 我正在使用并通过午餐全套英语和制作进行构建。它编译得很好,但SystemUI崩溃,第337行逻辑中出现IllegalArgumentException: mRecentsContainer = (ViewGroup) findViewById(R.id.recents_container); [...] if

我正在对AOSP SystemUI应用程序进行一些修改,并且在尝试在任意设备上运行它时遇到了一个非常特殊的问题:
findViewById()
返回
null
,而在其子项中导航则显示它确实存在

我正在使用并通过
午餐全套英语
制作
进行构建。它编译得很好,但SystemUI崩溃,第337行逻辑中出现IllegalArgumentException:

mRecentsContainer = (ViewGroup) findViewById(R.id.recents_container);
[...]
if (mRecentsContainer instanceof RecentsHorizontalScrollView){
    [...]
} else if (mRecentsContainer instanceof RecentsVerticalScrollView){
    [...]
}
else {
    throw new IllegalArgumentException("missing Recents[Horizontal]ScrollView");
}
稍微调试一下就会发现,
mrecentscocontainer
实际上是
null

我认为可能有一个布局正在膨胀,其中不包含该特定视图,因此为了检查,我使用
getChildCount()
getChildAt()
递归浏览了该视图的所有子视图。事实并非如此
@id/recents\u container
就在那里,有两层深:

> @id/recents_root (7f0e0070) [RecentsPanelView]: (2 children)
--> @id/recents_bg_protect (7f0e0071) [FrameLayout]: (2 children)
----> @id/recents_container (7f0e0072) [RecentsVerticalScrollView]: (1 children)
------> @id/recents_linear_layout (7f0e0073) [LinearLayout]: (0 children)
----> @id/recents_no_apps (7f0e0074) [FrameLayout]: (1 children)
------> [unnamed] (ffffffff) [TextView]
--> @id/recents_dismiss_button (7f0e0075) [View]
安装应用程序时,Logcat中会出现来自
system\u进程的单数提示:

12-11 22:38:01.090:W/ResourceType(165):获取包0中0x7f060000(t=5 e=0)的条目失败(错误-75)

检查
SystemUI\u intermediates
目录中的
R.java
会发现它指向一个看似不相关的
状态条\u recents\u app\u标签\u颜色
,这只是
res/values/color.xml
中定义的颜色


这是什么原因造成的?是不是因为我在没有编译的设备上运行布局,所以布局没有正确膨胀?我认为问题可能在于SystemUI对内部Android资源的引用,这些资源可能无法正确映射到我设备上的资源。这可能吗?

显然,一些生成的文件被卡住了

从头开始重建源代码,直到
makeclean
解决了它

或者,我发现删除以下中间目录有助于加快构建速度,但我不能100%确定这是否涵盖所有目录:

rm -rf out/target/product/generic/obj/APPS/SystemUI_intermediates/
rm -rf out/target/common/R/com/android/systemui
rm -rf out/target/product/generic/obj/APPS/framework-res_intermediates/
rm -f /out/target/common/R/com/android/internal/R.java
rm -rf out/target/product/generic/obj/PACKAGING/
rm -f out/target/product/generic/system/app/SystemUI.apk

我没有浏览代码,只是一个建议:可能您正在尝试在将dviewbyd添加到父级之前查找它。我提供的代码片段在
onfinishflate()
中执行,所以这应该不是问题所在。注意,代码直接来自AOSP的4.0.4_r2.1分支。