Components are not in class R

2

I am building a calendar, and for this I created a Activity where would be a list with all the contacts:

<LinearLayout 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:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".actContato">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <EditText
            android:id="@+id/edtPesquisa"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:hint="@string/lbl_hint_nome_pesquisa"
            android:inputType="textPersonName" />

        <ImageButton
            android:id="@+id/imb_ADD"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_add" />

    </LinearLayout>

    <ListView
        android:id="@+id/lstContatos"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

</LinearLayout>

And another Activity where all contacts would be registered:

<LinearLayout 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:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="aula4.com.example.raru.agenda.ActContatos">

    <LinearLayout
        android:id="@+id/lnlNome"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/txtNomeContato"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lblNomeContato"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/edtNome"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:ems="10"
            android:hint="@string/lbl_hint_nome"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/edtSobreNome"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/lbl_hint_sobrenome"
            android:inputType="textPersonName" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lnlTelefone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            android:id="@+id/txtTelefone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lblTelefone"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/edtTelefone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="phone" />

            <Spinner
                android:id="@+id/spnTelefone"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/lnlEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            android:id="@+id/txtEmail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lblEmail"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/edtEmail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="textEmailAddress" />

            <Spinner
                android:id="@+id/spnEmail"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lnlEndereco"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            android:id="@+id/txtEndereco"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lblEndereco"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/edtEndereco"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="textPostalAddress" />

            <Spinner
                android:id="@+id/spnEndereco"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lnlDatasEspeciais"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            android:id="@+id/txtDatas"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lblDatas"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/edtDatas"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="date" />

            <Spinner
                android:id="@+id/spnDatas"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lnlGrupo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            android:id="@+id/txtGrupos"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lblGrupos"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/edtGrupos"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="text" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

But when it comes to getting the reference in the java classes of both Activity ( findViewById() ), it is pointed out that there is no reference to the xml components.

I took a look at the R class and there really is no reference to them.

NOTE: I remembered that this error only happened after editing the menu xml, before I could even test the virtual machine, I removed all the modifications and left the xml as before:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="aula4.com.example.raru.agenda2.ActContatos">

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never" />
</menu>

e:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".actContato">

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never" />
</menu>

Errors:

    
asked by anonymous 28.07.2015 / 16:55

3 answers

1

Try the following, comment on or remove all rows with errors, give a clean in your project and then build. Probably the elements will reappear in class R.

The class R is automatically generated by having all the elements of its layouts in it, however in some types of errors in your code it may not be generated or not fully.

    
28.07.2015 / 17:05
1

The error is not in the class R or layout generation, but in the build.gradle file, that is, your project build configuration file. The two images you posted clearly show that the error has nothing to do with the layout. Be sure to correct the errors indicated in the lower left panel of the second image and correctly write your build file. Once everything is fixed, give a clean + rebuild to the project.

    
29.07.2015 / 04:00
0

Try two things:

In Android Studio, click "Build" and then "Clean Project" 2º Click again on "Build" click on "Rebuild Project"

See if it works out

    
04.09.2015 / 21:58