java - activity_main、menu、action_setting 无法解析或不是字段
问题描述
我刚刚开始使用 android,我的 hello world 应用程序遇到了问题,问题首先是它说 R 无法解决,我能够克服,因为没有 R.java 文件,我后来从互联网上复制了这些文件是三个错误 1.activity_main 无法解析或者不是字段 2.menu 无法解析或者不是字段 3.action_settings 无法解析或者不是字段
我已经尝试过 control+shift+o,已经尝试过 clean 和 build。
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
文件夹适当目录中的布局和菜单文件重建您的项目
推荐阅读
- r - 不能在循环中使用 poly(x)?“度”必须小于唯一点数
- php - How to get file extension from uploaded image with no extension in filename
- regex - Python 2:正则表达式在两个字符串之间的任意位置获取文本
- ios - 如何在按钮的帮助下显示图像时在视图中设置图像高度?
- c# - 需要重启IIS才能获取sql连接
- python - 在 Django 中动态添加上传处理程序的问题
- python - Python 中没有名为“ffnet”的模块
- apostrophe-cms - 在 Apostrophe CMS 中创建项目后如何创建管理员用户
- android - MP android图表线图布局参数
- c# - 如何检测取消的异步帖子