首页 > 解决方案 > 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);
}

}强文本

标签: javaandroideclipse

解决方案


您不应R.java手动创建或修改文件,因为它是由构建系统自动生成的。尝试从 Internet 上删除一个副本,然后使用位于res文件夹适当目录中的布局和菜单文件重建您的项目


推荐阅读