'R cannot be resolved to a variable' - gen folder is empty

前端 未结 14 2427
故里飘歌
故里飘歌 2021-02-13 22:34

I\'ve got an error:

R cannot be resolved to a variable

in line:

setContentView(R.layout.main);

but I can\'t r

相关标签:
14条回答
  • 2021-02-13 23:01

    Make sure that you are extending Activity class

    0 讨论(0)
  • 2021-02-13 23:03

    What you really need to do it just install "build-tools" from sdk manager, and r.java will be generated automatically in gen folder :)

    0 讨论(0)
  • 2021-02-13 23:06

    Check your res/ folder in order to be sure that every file it contains has no error. If any error exists R can not be generated.

    0 讨论(0)
  • 2021-02-13 23:06

    Clean your project once. It should build that file again automatically. Go to Project->Clean Of course, it will work ony if your xml files are syntactically correct!

    0 讨论(0)
  • 2021-02-13 23:11

    Simple

    Check that you have the same SDK - build version with your AndroidManifest and project.properties version.

    0 讨论(0)
  • 2021-02-13 23:12

    Try this: comment setContentView(R.layout.main); and the build/clean your project again. Then uncomment the commented line. This issue should not be seen then.

    0 讨论(0)
提交回复
热议问题