Cannot Resolve symbol R

后端 未结 8 1821
礼貌的吻别
礼貌的吻别 2021-01-18 07:02

I was working on Android Studio for adding a short toast message.(I was making an Android Wear Application)

I couldn\'t know why this code has error on \'symbol R\'

8条回答
  •  被撕碎了的回忆
    2021-01-18 07:27

    I know others have said most of these points, but this should serve as a sum-up and hopefully bring up some new solutions!

    If only the letter 'R' is red, it means there is something wrong with your R file (found at build\generated\source\r\debug\com\domain.projectname\R). Don't go around editing your R file- because each time the project is cleaned and built/rebuilt the R file regenerates (it completely resets without fail). There are a few possible solutions:

    1) You might have written import android.R; at the top of your Activity. You need to have a different R file imported. This means if your domain is "example" and your project name is "project" then your import should be: import com.example.project.R

    2) R is a build file. That means it disappears when you clean and generates anew when you build, as previously said above. Make sure you build or rebuild your project after cleaning it.

    3) Maybe your gradle project sync has not completed. Wait until all processes have finished running!

    4) It is also possible your R file is corrupt or missing. If the above don't work, you can come to this conclusion. It has a very easy fix, because as I explained earlier when you rebuild a new R file is generated. So just navigate to Build and click Clean project, then when that's finished, click Rebuild project. With the new R file your problems should be gone.

    P.S: It's nearly impossible to give an accurate answer without all relevant code provided

提交回复
热议问题