Reputation: 61
I'm trying to learn android on android developer website. However I encounter an error when following their lecture. It seems that the findViewByID cannot resolve R.id.editText despite I'm just typing from their website. Can someone helps, thanks
public void sendMessage(View view) {
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);
}
Here is the error message: "Error:(22, 57) error: cannot find symbol variable editText".
Upvotes: 0
Views: 2604
Reputation: 12803
It seems that the findViewByID cannot resolve R.id.editText
You are probably missing to define EditText
id as editText
.
<EditText
.....
android:id="@+id/editText"
.....
/>
YourCurrentActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
......
}
Upvotes: 0
Reputation: 73
Just do one thing , remove this from sendMessage function and
EditText editText = (EditText) findViewById(R.id.editText);
place this line right below setContentView(R.____);
I guess , this will solve your problem
Upvotes: 1