尝试在"R 中的 id"中添加符号时出现 IDE 错误



R.id上的"toolbar"、"name"one_answers"press"均为红色,无法找到。我已经重新安装了应用程序。

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mNameText = (EditText)findViewById(R.id.name);
Button button = (Button) findViewById(R.id.press);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
handleButtonClick();
}
});
}
private void setSupportActionBar(Toolbar toolbar) {
}
private void handleButtonClick() {
mNameText.setText("The button was clicked");
}

当我试图在"R中的id"中为它们创建字段时,我会遇到IDE错误。

R是在构建应用程序时生成的类。不能直接在其中添加字段。共享您的完整"活动"及其XML文件,以便我们能够为您提供更多帮助。

首先,确保"name"、"press"one_answers"toolbar"是activity_main.xml文件中相应元素的id。

如果已经安排好了,有时只需重新构建项目就可以修复这个错误。从Android Studio工具栏转到构建->清理项目。完成后,执行"构建"->"重建项目"。

最新更新