Kvaibhav01 Kvaibhav01 - 4 months ago 377
Android Question

Cannot resolve symbol 'menu' errors in Android Studio

I'm learning Android Development for Beginners from Udacityand have completed making an app named Court Counter in which I wrote code for an XML (activity_main.xml) and some code for Java (MainActivity.java) file as some of the code was provided by the Udacity team on Github.

But when I click on 'Build APK' I get two errors both from the Java file:


  1. Cannot resolve symbol 'menu' in the following 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;
    }






    1. Cannot resolve symbol 'action_settings':-






@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();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}





I don't know what happens when these block of code are executed but I want to run the app on my phone! Please help.

Thanks,
Kvaibhav01.

Answer

I just deleted the part of code that had error:

@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();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

After that there were no more errors and I was able to run the app! Thanks everyone who gave me their views on this!

Kvaibhav01.