1

I have pasted following code in style.xml, replacing previous default code in style.xml, and I am getting following Error in `MainActivity.Java':

Error cannot resolve symbol 'R' of R.id.toolbar

I am new android developer, Please support!

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Primary theme color of the app (sets background color of app bar) -->
    <item name="colorPrimary">#FF9800</item>
    <!-- Background color of buttons in the app -->
    <item name="colorButtonNormal">#FF9800</item>
</style>

</resources>
Pete
  • 57,112
  • 28
  • 117
  • 166
ayazk
  • 43
  • 1
  • 5

4 Answers4

1

If cleaning and rebuilding doesn't work, try File->Invalidate Caches/Restart->Invalidate and Restart.

ben_joseph
  • 1,660
  • 1
  • 19
  • 24
0

If you're user of Android Studio. Try to:
Build -> Clean Project
Build -> Rebuild project

See this: Android Studio marks R in red with error message "cannot resolve symbol R", but build succeeds

Community
  • 1
  • 1
Anton Shkurenko
  • 4,301
  • 5
  • 29
  • 64
0

if you are using android studio first check your build.gradle file to make sure that you have compiled appcompat support library in your project. if not add this in order to add the library to your project

compile 'com.android.support:appcompat-v7:23.1.1'

and after that clean and build project.

slenderm4n
  • 292
  • 7
  • 15
  • com.android.support:appcompat-v7:23.1.1 already present in build.gradle in dependencies – ayazk Dec 10 '15 at 11:25
-1
import android.R;

import this in your MainActivity. Then GOTO Build---> Clean Project

Abhishek
  • 1,654
  • 2
  • 18
  • 31
  • After import android.R; and then cleaning the project, previous error of 'R' seems resolved but now same Error (can't resolve the symbol) is appearing on many other characters like in ' R.Layout.activitymain' : it is appearing for 'activitymain' – ayazk Dec 10 '15 at 11:17
  • may the name of your xml layout is diffrent as mentioned in MainActivity.Java check it out Try it as activity_main – Abhishek Dec 10 '15 at 11:40
  • adding `android.R` can never be a solution.. It refers to the default resources provided by Android.. Not the layout and styles we have added explicitly..!! – Janki Gadhiya Jun 20 '16 at 08:47