0

I just installed Android Studio following the steps 1 by 1. All JDK and everything is installed.

I started a new project and created a blank activity and it started off with the error "Cannot resolve R".

I have tried cleaning the project and restarting the program and it did not help.

All the articles and search results I find on this topic say that cleaning the project should fix it. But I'm still stuck. :(

2 Answers2

1

I would guess it's either:

  1. You have no resources (drawables, layouts, etc) in your "res" dir. Workaround: create a dummy strings.xml file or something.
  2. Your class' package name is different from your application's package name (in which case, you have to import the R class from com.example.mypackage)
Snild Dolkow
  • 6,669
  • 3
  • 20
  • 32
  • 1
    I checked the res directory and such and did a couple more cleans for good measure. Now it isnt the R that is listed in red, it says that appcompat cannot be resolved. EDIT: And ActionBarActivity –  May 16 '15 at 20:27
  • 1
    appcompat is the backwards compatibility library: https://developer.android.com/tools/support-library/features.html#v7-appcompat I think adding `com.android.support:appcompat-v7:21.0.0` into the dependencies section of your (app) build.gradle should do the trick. – Snild Dolkow May 16 '15 at 20:30
  • 1
    Ok, I added that to the dependencies. Did a rebuild and a clean. I THINK that the only remaining issue is the ActionBarActivity –  May 16 '15 at 20:33
  • What's the issue with ActionBarActivity? It should've been included with the support library dependency, so it should not be a problem. It *is* deprecated, though -- the recommendation is to use AppCompatActivity instead. Are you just getting a warning about that? – Snild Dolkow May 16 '15 at 20:38
  • (BTW, a tip about asking for help: clear and thorough information will help you get a better answer faster. For example, I wouldn't have had to guess as much or ask for more info if you'd included the exact error message, and perhaps the immediate code surrounding the problem.) – Snild Dolkow May 16 '15 at 20:38
  • I apologize: The following classes could not be found: - android.support.v7.internal.widget.ActionBarOverlayLayout. It says "Rendering Problem" and wont show me the design display. –  May 16 '15 at 20:40
  • That one is new to me, but just googling "android.support.v7.internal.widget.ActionBarOverlayLayout" yields [this StackOverflow post](http://stackoverflow.com/questions/29062658/rendering-problems-in-android-studio-v-1-1-0) with a couple of proposed solutions/workarounds. See if any of those fit you. – Snild Dolkow May 16 '15 at 20:44
  • I appreciate the help. It seems to have fixed the issue by changine ActionBarActivity to AppCompatActivity and importing it's class. –  May 16 '15 at 20:48
-1
  1. Invalidate cache and restart
  2. clean the build

Try to re-run, the app will work smoothly<

Matthias
  • 4,481
  • 12
  • 45
  • 84
Sagar Bhatnagar
  • 486
  • 2
  • 11