0

I tried to create a new android project using Eclipse but I got an error in R. I must remind that I did not modify any code and I simply created a project. the error is in the following code and it says :"R cannot be resolved to a variable"

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

After trying out all possibilities, I decided to replace/re-install my eclipse with another and reinstalled the ADT. But when I did this I understood that the appcompat_v7.jar file couldn't get created in the folder of bin in the project and when I tried to add this file to bin directory and then tried to clean the project. The jar file vanished. After all these; should I reinstall another ADT?. What should I do ? I will be very happy if any one help me. Thanks.

keshav kowshik
  • 2,354
  • 4
  • 22
  • 45
bety
  • 21
  • 4
  • 1
    possible duplicate of [R cannot be resolved - Android error](http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error) – germi May 21 '15 at 10:10
  • No need to reinstall another ADT. Check for the missing files. – Kailas May 21 '15 at 10:14

2 Answers2

0

Use following steps to remove .R files error that are

case 1

Add support v7 library to use that kind of themes(Theme.AppCompat.Light.DarkActionBar)

you need to add appcompat v7 as library project

if your style has an error eclipse does not generate R.java file

case 2

These problem occurs mainly when you are doing these things:

Whenever android.R file is imported BY DEFAULT or BY YOURSELF in yours code than delete these line using (CONTROL+D) than after clean build the project. And than after when you move cursor on the line like setContentView(R.layout.your_layout) on "R" than eclipse give you two option first is import android.R and another import YOUR_PROJECT_NAME.R THAN YOU SHOULD HAVE SELECT THE SECOND ONE AND RESOLVE YOUR PROBLEM.

The problem can be occur when you do something wrong in the layout(in the xml file) than correct it and than again clean and build project.

Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103
0

i think can you import android.R in your class activity file,

so remove it and try to import your package R file