[英]Cannot resolve symbol “content_frame”
I seem to have a rather persistent error with my android studio. 我的Android Studio似乎有一个相当持久的错误。 In each project I get the error cannot resolve symbol "content_frame" in lines like
在每个项目中,我得到的错误无法解析如下行中的符号“ content_frame”
fragmentManager.beginTransaction().replace(R.id.content_frame, new Setting_new()).commit();
I already did a "invalidate cache and restart", followed by a clean project and a rebuild project. 我已经进行了“无效的缓存并重新启动”,然后执行了一个干净的项目和一个重建项目。 While doing the rebuilding it gave the error
进行重建时出现错误
Compilation failed; see the compiler error output for details.
And on the right it said error: cannot find symbol variable content_frame
I don't know if it is the error output the other message was mentioning. 并在右侧显示错误:
cannot find symbol variable content_frame
我不知道这是否是另一条消息所提及的错误输出。
Like I mentioned it is in each project, I made a new project with a menu drawer and just added this to the drawer and it gave an error. 就像我在每个项目中提到的那样,我创建了一个带有菜单抽屉的新项目,并将其添加到抽屉中,但出现了错误。 I've also downloaded a new installer and reinstalled android studio with it but it made no difference.
我还下载了一个新的安装程序,并用它重新安装了android studio,但这没什么区别。
You are trying to add fragment using 您正在尝试使用添加片段
fragmentManager.beginTransaction().replace(R.id.content_frame, new Setting_new()).commit();
where container R.id.content_frame
is the id of the View
where your Setting_new
will be displayed(added). 其中容器
R.id.content_frame
是将在其中显示(添加) Setting_new
的View
的ID。
Add Container View
in your Activity's xml file, something like... 在活动的xml文件中添加
Container View
,类似...
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
The issue is here: fragmentManager.beginTransaction().replace(R.id.content_frame, new Setting_new()).commit();
问题在这里:
fragmentManager.beginTransaction().replace(R.id.content_frame, new Setting_new()).commit();
Make sure that your FrameLayout, in which to add the Fragment exists in your .xml file: 确保.xml文件中存在用于添加片段的FrameLayout:
<!-- Frame Layout for Fragments -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?android:actionBarSize"/>
It is trying to look for the id content_frame
where your fragment would be loaded. 它正在尝试查找将要加载片段的id
content_frame
。
You can use something like below in your Activity's xml file:- 您可以在“活动”的xml文件中使用以下内容:-
<FrameLayout
android:id="@+id/content_frame" // ----------> id where fragment would be loaded.
android:layout_width="match_parent"
android:layout_height="match_parent"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.