我刚刚开始使用 android,我的 hello world 应用程序遇到了麻烦,问题首先是它说 R 无法解决,但我能够克服,因为没有 R.java 文件,我后来从互联网 现在有三个错误 1.activity_main无法解析或者不是字段 2. 菜单无法解析或不是字段 3.action_settings无法解析或者不是字段
我已经尝试过control+shift+o, 已经尝试过清理和构建。
package my.hello;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}强文字
最佳答案
您不应手动创建或修改 R.java
文件,因为它是由构建系统自动生成的。尝试删除从 Internet 复制的一份文件,然后使用位于 res
文件夹的相应目录中的布局和菜单文件重建项目
关于java - Activity_main、菜单、action_setting 无法解析或不是字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55306705/