-1

//R. gives error of "R cannot be resolved to a variable". i am trying to make a simple program but when i create the project it displays that "R cannot be resolved to a variable".

package com.example.ghanshyam;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    //R cannot be resolved to a variable
    }


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

}
user3153156
  • 17
  • 1
  • 6

3 Answers3

0
  1. After installing Android SDK Tools, you should install Android SDK Build-tools using Android SDK Manager
  2. Try adding some whitespace in androidmanifest.xml and then save the file
  3. Try Clean and Rebuild the project
albusshin
  • 3,930
  • 3
  • 29
  • 57
0

Try this, it has worked for me:

Right-click on the Project root --> Android Tools --> Fix Project Properties
vincent091
  • 2,325
  • 4
  • 17
  • 21
0

Dont worry. First you may clean the project, then run the project. If this does not work then follow the following links:

Here is the best way to solve this problem: Android Development- Where is my R.Java file?

R cannot be resolved - Android error

R cannot be resolved to a variable

R cannot be resolved to a variable -- mailing list entry

Fixed: R cannot be resolved to a variable

Community
  • 1
  • 1
learner
  • 3,092
  • 2
  • 21
  • 33