android学习——Cannot resolve symbol ‘editText‘

EditText editText =(EditText)findViewById(R。 id.editText); 在“((R.id.editText))”发生错误Cannot resolve symbol ‘editText’

今天跟着android studio 开发文档学习时发生错误,在启动另一个activity中,构建一个intent时,https://developer.android.google.cn/training/basics/firstapp/starting-activity#java

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

解决方法,查看activity_main.xml,文本编辑框部分

将sendMessage方法中editText改为对应的,我这里是editTextTextPersonName3,如图

public void sendMessage(View view) {
        Intent intent = new Intent(this, DisplayMessageActivity.class);
        EditText editText = (EditText) findViewById(R.id.editTextTextPersonName3);
        String message = editText.getText().toString();
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);
    }

你可能感兴趣的:(android学习——Cannot resolve symbol ‘editText‘)