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

前端 未结 14 2413
故里飘歌
故里飘歌 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:00

    Try this:

    1. First disable automatic build option from Project>Build Automatically
    2. Change eclipse work space
    3. Create a new Hello World test project
    4. Comment setContentView(R.layout.main);
    5. Build project manually by right click on your project in eclipse>Build project
    6. Check whether R.java in gen folder has been generated
    7. If yes, then uncomment setContentView(R.layout.main);
    8. Now build project again manually and run

    This should resolve the problem hopefully.

提交回复
热议问题