16

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.

3
  • did you have container id in your xml file and in activity_quiz layout? Feb 12, 2014 at 7:45
  • 3
    you must add android:id = "@+id/container" to your layout Feb 12, 2014 at 7:49
  • 1
    @Shayanpourvatan please post it as answer, user1796309 please accept when it's posted.
    – Spons
    Feb 12, 2014 at 7:58

2 Answers 2

20

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

1
  • For a newbie like me, people could mention that the xml should be src/main/res/layout/activity_main.xml.
    – kakyo
    Aug 6, 2019 at 6:05
7

Adding android:id="@+id/container" to your RelativeLayout will remove the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.