"Unable to allow or not field"

I had this problem since I tried programming on Android (newbie here). Android programming recently started 2 weeks ago. Testing this ( http://startandroid.ru/en/lessons/complete-list/225-lesson-19-creating-a-simple-calculator.html ) and problems arose with the sample R.id: R.id. etNum1

"etNum1 cannot be resolved or is not a field

Here is my code:

etNum1 = (EditText) findViewById(R.id.etNum1); etNum2 = (EditText) findViewById(R.id.etNum2); btnAdd = (Button) findViewById(R.id.btnAdd); btnSub = (Button) findViewById(R.id.btnSub); btnMult = (Button) findViewById(R.id.btnMult); btnDiv = (Button) findViewById(R.id.btnDiv); 

XML for buttons and text:

 <EditText android:id="@+id/etNum1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:ems="10" > <requestFocus /> </EditText> <EditText android:id="@+id/etNum2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText1" android:layout_below="@+id/editText1" android:ems="10" /> <Button android:id="@+id/btnSub" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button1" android:layout_alignBottom="@+id/button1" android:layout_toRightOf="@+id/button1" android:text="Subtract" /> <Button android:id="@+id/btnMult" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button2" android:layout_alignBottom="@+id/button2" android:layout_toRightOf="@+id/button2" android:text="Multiply" /> <Button android:id="@+id/btnDiv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button3" android:layout_alignBottom="@+id/button3" android:layout_alignParentRight="true" android:text="Divide" /> <Button android:id="@+id/btnAdd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/editText2" android:layout_marginLeft="36dp" android:text="Add" /> <TextView android:id="@+id/tvResult" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/button2" android:layout_centerHorizontal="true" android:layout_marginTop="14dp" android:text="Answer" android:textAppearance="?android:attr/textAppearanceLarge" /> 
+4
source share
3 answers

Most likely you are importing an android.R class instead of your R class application

Instead of this

 import android.R; 

import it

 import yourPackage.R; 
+4
source

You can also Clean (Project → Clean ...) to execute a project to restore the R file and see if this problem has resolved.

+1
source

R does not recognize etNum1. Create your code. He will work like magic. Since R will be updated after assembly

0
source

Source: https://habr.com/ru/post/1490502/


All Articles