Java R.id.container 未解决
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21721648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
R.id.container not resolved
提问by Alexander
I bought book Bill Phillips & Brian Hardy "Android programming the big nerd ranch guide". And in the first chapter, I created Gradle solution using idea instead eclipse. This project generated by idea doesn't compile.
我买了一本书 Bill Phillips & Brian Hardy “Android 编程大书呆子牧场指南”。在第一章中,我使用idea而不是eclipse创建了Gradle解决方案。这个idea生成的项目无法编译。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new DummyFragment())
.commit();
}
}
xml:
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".QuizActivity$DummyFragment">
<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
error: cannot find symbol variable container
错误:找不到符号变量容器
I have not changed anything, but project doesn't compile
我没有改变任何东西,但项目没有编译
Please help me.
请帮我。
采纳答案by Shayan Pourvatan
as i mention in comment you must add following code in to your layout:
正如我在评论中提到的,您必须将以下代码添加到您的布局中:
android:id = "@+id/container"
you get that error because you don't have container
id in your xml
file
您收到该错误是因为您container
的xml
文件中没有id
回答by Chintan Soni
Adding android:id="@+id/container"
to your RelativeLayout will remove the error.
添加android:id="@+id/container"
到您的 RelativeLayout 将消除错误。