Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "Cannot resolve Symbol editText" in Android Studio MyFirstApp tutorial

I'm new to Android Studio and Android development. So I was following the tutorial given by developer.android.com and I'm having an error in this line : EditText editText = (EditText) findViewById(R.id.editText); The error is saying that : cannot find symbol variable editText .

This is part of my code :

import android.os.Bundle;
import android.widget.EditText;


public class MainActivity extends AppCompatActivity {
   
    public void sendMessage(View view){
        EditText editText = (EditText) findViewById(R.id.editText);
        String message = editText.getText().toString();

    }
}
like image 903
luna.t Avatar asked Dec 13 '22 21:12

luna.t


1 Answers

Make sure that you have assigned the id for your EditText in the activity_main.xml as below:

<EditText
    android:id="@+id/editText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
like image 187
Chithra B Avatar answered Jan 13 '23 11:01

Chithra B