无法在片段的 onCreateView 中膨胀布局

cannot inflate layout in onCreateView of fragment

在我的 MenuContentActivity 中,我调用 IntercomFragment 如下:

IntercomFragment myContent= IntercomFragment.newInstance(index);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(android.R.id.content, myContent, "intercomFrag").commit();

然后在我的 IntercomFragment 中,我尝试膨胀布局“intercom”,但它失败了!它抛出“java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycompany.myapp/com.mycompany.myapp.MenuContentActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030030

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View mainView = inflater.inflate(R.layout.intercom, container, false);
......
......
......
}

inflater.inflate 失败。 R.layout.intercom存在,intercom.xml已经在布局目录中。 我可以用同样的方式调用和显示我的其他片段,但我不明白为什么我不能用同样的方式调用和显示 IntercomFragment。 这是什么错误,知道吗?

我意识到我的应用程序不会在 landspace 模式下崩溃然后我怀疑是 intercom 布局本身。

该布局包括其他具有 <include layout=""......\>

的布局

我意识到包含的布局之一只有 landspace 文件(在 layout-land 文件夹中)。所以我猜是因为加载布局文件时找不到包含布局的 portrait 版本,所以它失败了。

我刚刚添加了缺少的布局文件,现在已经解决了!