猿问

setText() 错误,TextView 方法无法解析

方法无法解析此代码中的 TextView 这有

什么问题?


public class MainActivity extends AppCompatActivity {


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);


    }


    EditText Username = (EditText) findViewById(R.id.EmployerNameEdit);


    String userName = Username.getText().toString();

    TextView changedName = (TextView) findViewById(R.id.employerName);

    changedName.setText(userName);


}


慕斯王
浏览 235回答 2
2回答

阿晨1998

可能是你错过了大括号,公共类 MainActivity 扩展 AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    EditText Username = (EditText) findViewById(R.id.EmployerNameEdit);    String userName = Username.getText().toString();    TextView changedName = (TextView) findViewById(R.id.employerName);    changedName.setText(userName);}}如果您仍然遇到问题,请随时提出问题。:)

慕盖茨4494581

oncreate 或 create global edittext 和 TextView 中的每件事@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main); EditText Username = (EditText) findViewById(R.id.EmployerNameEdit);String userName = Username.getText().toString();TextView changedName = (TextView) findViewById(R.id.employerName);changedName.setText(userName); }
随时随地看视频慕课网APP

相关分类

Java
我要回答