Android - activity_main cannot be resolved or is not a field

1) Where does your layout file exist? is it under layout folder then shouldn't it be

R.layout.activity_main

2) You still have to import your projects R file

com.example.mapssample.R;

3) R file is automatically generated if there's no error in your code. Sometimes when you get can't resolve R file error means you have problem somewhere else in the project. Try clean project. It might help.

4) You don't really need menu for testing this project. Also the activity_main file you showed is already included in the project and that's in layout folder. Just comment the menu part and see.


Your Code imported android.R so first remove this line import android.R;

so remove this line & press cntrl+shift+o (to import necessary packages)..