Play framework tutorial: Cannot resolve symbol 

2019-02-01 20:31发布

I followed a tutorial here and although I got the entire tutorial working just fine, one of the classes in my IntelliJ project is marked with "red warnings". I cannot figure out what the problem is here? The project works but it shows these warnings? Any ideas on what this is and how to fix it? In the tutorial, about 3.5 minutes into it, the red marks magically disappear and the video presenter doesn't explain it.

enter image description here

7条回答
太酷不给撩
2楼-- · 2019-02-01 20:59

This process worked for me:

  1. go into [File -> Project Structure -> Modules -> [YourAppModule] -> Sources Tab]
  2. navigate to the "target/scala-[version]/src_managed" directory (panel on the right).
  3. Right click the "main" directory and flag it as a source folder.
  4. Right click "controllers" and "views" and remove the "sources" flag (you should see the controllers and views folder become package directories).
  5. Apply -> OK -> recompile.

from https://github.com/playframework/playframework/issues/1784#issuecomment-26345523

查看更多
Explosion°爆炸
3楼-- · 2019-02-01 20:59

Views / templates are not classes, which is why IDE cannot recognize them. IDE should be configured to look for the compiled version of the views. This click will fix your issue

enter image description here

查看更多
仙女界的扛把子
4楼-- · 2019-02-01 20:59
  1. Open "Project" sidebar
  2. Go to target/scala-<version>/src_managed
  3. Right-click the src_managed, "Mark Directory As"/"Generated Source Root"
  4. Subdirectories of src_managed are from a strange reason marked as source roots. You can disable it.
  5. Enjoy.

Note that javascript routes seem to be still ignored from a strange reason, so this is not a perfect solution. Nevertheless, it is better than nothing.

查看更多
Summer. ? 凉城
5楼-- · 2019-02-01 21:01

Go to the Run configuration for your Play project and remove the 'Make' step from the "Before Launch" section. Then, IntelliJ would simply run the Play project without attempting to compile, and the views will get compiled automatically.

Until the views are compiled, IntelliJ doesn't know they exist, and can't make the project itself. Clearly this is a problem with IntelliJ's plugin, but since you're already relying on Play to do your compiling dynamically, this workaround doesn't hurt the workflow too much.

查看更多
三岁会撩人
6楼-- · 2019-02-01 21:02

I managed to make it work on IDEA Community 14 by solely cleaning IDEA cache (File -> Invalidate Caches / Restart)

查看更多
做自己的国王
7楼-- · 2019-02-01 21:23

The routes file and the views are compiled only when the project is first loaded in the browser. Till then, IntelliJ shows the error as it cannot find those classes. But the errors magically dissppear when you run the application and load it into browser.

You can verify this in the play console. After you do a play run , and load the url localhost:9000 in the browser, you can see compilation messages in the play console saying

...compiling 22 scala sources....

查看更多
登录 后发表回答