public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.editText);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
I just started Android prog! so i am following this guide "Start Another Activity" fro google: https://developer.android.com/training/basics/firstapp/starting-activity.html Error occurs in this line EditText editText = (EditText) findViewById(R.id.editText); In the "(R.id.editText)" part! so if someone can explain why & how am getting this error it will be greately helpful! Thanks in advance!
I'm coming to this late, but adding this for those who find this searching for the answer. Here's the heart of the "cannot resolve symbol 'editText'" problem. In activity_main.xml, when creating the text edit box, the editor may append a number to the id:
<EditText
android:id="@+id/editText3"
If you either remove the number, or edit the reference in MainActivity.java to match it, it works.
Note, if you remove the number, then you need to also remove it (in the same file) at:
<Button
...
app:layout_constraintBaseline_toBaselineOf="@+id/editText3"
app:layout_constraintLeft_toRightOf="@+id/editText3"
as well, or the contraints won't connect.
Really something they should have noted in the tutorial.
On the flip side, I think I learned more from figuring this out than the rest of the tutorial so far.
Because you have't imported fallowing
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With