Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R.id.container not resolved

Tags:

java

android

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.

like image 464
Aleksandr Avatar asked Feb 12 '14 07:02

Aleksandr


People also ask

What is r id container?

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.

What is r id in android Studio?

the rest of that Android.R.id tells the code to find an Android resource with an Id of 'text1' for example.

How does r id work?

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.


1 Answers

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

like image 62
Shayan Pourvatan Avatar answered Oct 02 '22 20:10

Shayan Pourvatan