R cannot be resolved to a variable

后端 未结 29 1217
不知归路
不知归路 2020-11-28 14:14

I would like to fix this error

R cannot be resolved to a variable

I looked up many answers, but I could not get the right one;

29条回答
  •  忘掉有多难
    2020-11-28 14:48

    Simple Solution:

    Check whether in gen[generated Java Files], under your project package, there is a R.java file.

    If no,

    1. There is some errors in xml files you have added or modified. check that deeply. Fix all yellow lints and go through the error log and console
    2. Check your xml files should be small letter, '_' and digits.
    3. Check your image names you have added also should be small letter, '_' and digits.
    4. Clean the project.
    5. Check R.java created. if yes, and still error occurs, follow the yes instructions below, else check xmls once again

    If yes,

    1. replace the 'import android.R' by your project package.R ex: 'com.mysmallapp.main.R' in all files.
    2. Clean the project

提交回复
热议问题