activity_main,menu,action_setting无法解析或不是字段

问题描述 投票:0回答:1

我刚刚开始迈向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);
}

强文

java android eclipse
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.