0

Why I can only create android project that compile with API 21 or API 22? other than this 2, all will have error with R cannot be resolved, and if I import android.R, it will give me another error which is activity_main cannot be resolved or is not a field. I search for solution from Google but all doesn't work for me. Help me please. R cannot be resolved to a variable


and here is the error if I import android.R activity_main cannot be resolved or is not a field

and if I change to avtivity_list_item there still have error.

Newbie
  • 1,584
  • 9
  • 33
  • 72
  • Firstly, never import android.R especially as it has no relevance to your own R.java class. Secondly, for your firat (actual) error about "R cannot be resolved to a variable" - it will be because your R.java file is not being auto-generated - you can check your project's /gen folder to confirm this. The usual reason R.java isn't generated is there is a fatal exception at build time - check the Console, it should give further information. Also, try to Clean and Rebuild your project which can sometimes fix problems with R.java not being auto-generated. – Squonk Apr 04 '15 at 07:59
  • Are you changing the build tools version or the target version? Have you installed the right build tools in the SDK manager? – Daniel Lubarov Apr 04 '15 at 10:00
  • @Squonk yes, the R.java file is not generated. I can't find it in the gen folder, so how? – Newbie Apr 05 '15 at 12:35
  • @AhYong : As I said in my comment - check the Console output when you attempt to build - it should give more detailed information. – Squonk Apr 05 '15 at 17:06

1 Answers1

0

Well for the first error: check your SDK Manager to see if you have the the 4.2.2(API 17) installed.

And for the second: I had this problem sometime ago, all you have to do is clean your project and build it again as this answer suggests link, see if that helps.

Community
  • 1
  • 1
M090009
  • 1,129
  • 11
  • 20