Nicolas Nicolas - 1 month ago 6x
Android Question

Android Studio: can not resolve symbol "R"

I know this question has been asked several times, but no answers are useful due to my context. The thing is, I just opened my first project (in my actual computer) and without editing anything all the "R." in the turn red. Do anyone know what are the causes for this problem and how it can be fixed?

Here is the .java main activity

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {

protected void onCreate(Bundle savedInstanceState) {

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

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 == {
return true;

return super.onOptionsItemSelected(item);

and this is the .xml layout:

<RelativeLayout xmlns:android=""
xmlns:tools="" android:layout_width="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />


I haven't modified the code or anything. I'm using Android Studio. Does anyone know how to fix it?


There are a couple of things that it could be:

1. You may need to do a clean & build
2. You may need to update the SDK (Go into your SDK manager, and make sure that all your files are up to date)

I find that this happens mostly when I update AS, and when you do the AS update, you also need to update the SDK via the SDK manager. Be sure that your tools are also up to date, and not just the API. Things like and will cause this error. Check the Run tab at the bottom left, as that should give you an idea if something is out of date, and you need to update. If you are using libraries, they may have been updated as well.

You also want to check your build.gradle file inside your mobile directory and make sure that the dependancies are inline with your SDK via the SDK manager. This is usually the culprit for me, especially when I update AS.

Unfortunately, there is no "easy" solution for this. You are just going to have to try different things until you find it, because it could be as simple as doing a "clean & build".

Good luck!