简体   繁体   中英

Android Studio: Why won't the options menu embedded on layout show on my emulator/preview?

Error says:

This project contains Java compilation errors, which can cause rendering failures for custom views. Fix compilation problems first.
The following classes could not be found: item and menu

图像1

And why is the java class for that layout is showing plenty of "Cannot resolve symbol R"?

图像2

I'm not sure why the xml file and java class are not compiling. I appreciate any feedback from you guys.

You cannot have a layout of a menu inside the layout of an activity. It must be defined separately in an XML file inside the res/menu/ directory, in a similar way as your main_options_menu.xml file is defined.

The reason for getting the cannot resolve symbol R error is because the Gradle build did not complete (due to an error). To fix it, either build or clean the project after removing all errors. You may check out "cannot resolve symbol R" in Android Studio .

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