简体   繁体   中英

activity_main, menu, action_setting cannot be resolved or is not a field

I am just getting started towards android and i am having trouble with my hello world app, The problem is first it said R cannot resolved which i was able to overcome because there was no R.java files which i later copied from the internet now there are three errors 1. activity_main cannot be resolved or is not a field 2. menu cannot be resolved or is not a field 3. action_settings cannot be resolved or is not a field

I have already tries control+shift+o, already tried clean and 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);
}

} strong text

You should not create or modify R.java file manually as it's autogenerated by build system. Try to remove one copied from Internet and just rebuild your project with layout and menu files located in appropriated directories of the res folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM