Ronit
Ronit

Reputation: 11

Cannot Resolve R.menu and other R. stuff in Android Studio

I have been practicing in Android Studio as per the android app development free course in UDACITY. And wherever there is a R.menu or R. stuff it cannot be resolved

package com.example.android.courtcounter;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.R;

public class MainActivity extends AppCompatActivity {

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

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

    return super.onOptionsItemSelected(item);
}

/**
 * Displays the given score for Team A.
 */
public void displayForTeamA(int score) {
    TextView scoreView = (TextView) findViewById(R.id.team_a_score);
    scoreView.setText(String.valueOf(score));
}
}

Plz help how to solve this Issue.

Upvotes: 0

Views: 2272

Answers (2)

prGD
prGD

Reputation: 1511

remove import android.R; clean and rebuild it. if it still doesn't work try this

import com.example.android.courtcounter.R;

Check you AndroidManifest.xml, check the package name there. use that as import .R; in code.

Upvotes: 1

Ali Bdeir
Ali Bdeir

Reputation: 4365

  1. Clean and rebuild your project by going to Build>Clean Project.
  2. Go to File>Invalidate Caches/Restart.
  3. Make sure you built your project, and make sure there aren't any errors (red lines) in the res directory.

Upvotes: 7

Related Questions