0

I am new to Android Java programming. Trying to make a simple app. All goes smootly until i want to add a menu... This is how i tried: After that I added the code

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

No errors, but than any changes I do to menu_main.xml dont go to the app. After a lot of head-scraching i realised Android Studio doesnt read this file... The only way to force it to read the file is to "Reformat Code" on the entire app... Everytime i change this file i have to do it... Restarting Android Studio (even my PC and phone tbh) didnt work. Removing this file didnt help either (AS doesnt even notice the file is gone until I "Reformat Code"). Im guessing that because I manually add this file than it doesnt register as part of the app...? Any help would be appreciated. Thanks!

1 Answer 1

0

if You have problem's like that try to Rebuild Project,

enter image description here

or remove folder 'projectname/app/build'. Temporary file build.

If that won't help You can Invalidate Caches/Restart

enter image description here

3
  • "Rebuild Project" gives temporary solution... I'd have to click it everytime I change that xml file. The other solutions dont work at all... wish there was a way to force the rebuild on every app run Commented Nov 24, 2019 at 16:55
  • If You have older version of Android Studio, You can try to disable Instant Run. If it won't help try to disable 'Power Save Mode', Ctrl+Shit+A and type 'Power Save'.
    – SmaQu
    Commented Nov 24, 2019 at 17:19
  • latest versian of Android Studio, disabled instant run and same, power save was never on... i believe Android Studio keeps a list of all files relevant to the project and siply doesnt add the xml to that list Commented Nov 24, 2019 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.