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.
@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:
<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.
It simply adds a Fragment to the 'container' you've declared in your xml layout. Since you've added a layout in e.g. onCreate() the compiler knows which layout is the correct one. Add: 'container' is just a name or an id.
the rest of that Android.R.id tells the code to find an Android resource with an Id of 'text1' for example.
Android R. java is an auto-generated file by aapt (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory. Whenever you use any recourse in you project then its one Unique Id will be generated automatically and you can identify that resource by using that id.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With