Search code examples
androidmobile-application

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();

    }
}

Solution

  • 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" />