Play Framework 2.2.1 - Compilation error: “method render in class index cannot be applied to given types;”

后端 未结 3 797
[愿得一人]
[愿得一人] 2020-12-20 22:17

I am new to Play Framework, and attempting to build a Todo-list from this manual.

When I try to run the application I get the error:

Compilation          


        
3条回答
  •  既然无缘
    2020-12-20 22:54

    Most probably your package is models NOT Models isn't it?

    BTW this package is autoimported so you can just use:

     @(tasks: List[Task], taskForm: Form[Task])
    

    Hm, changes... Actually log in the console says everything

    [error] /www/play20apps/testing/Todo-List/app/controllers/MainController.java:24: error: method render in class index cannot be applied to given types;
    [error]         return ok(views.html.index.render(Task.all(), taskForm));
    [error]                                   ^
    [error]   required: List,play.api.data.Form
    [error]   found: List,play.data.Form
    [error]   reason: actual argument play.data.Form cannot be converted to play.api.data.Form by method invocation conversion
    [error] 1 error
    

    especially these lines:

    [error]   required: List,play.api.data.Form
    [error]   found: List,play.data.Form
    

    TBH I didn't ever test the Activator but it looks that imports play.api.data.Form into views, which is incorrect for Java controllers. solution is full qualified path for Form:

    @(tasks: java.util.List[Task], taskForm: play.data.Form[Task])
    

    As mentioned in comment *.api.* imports are for Scala and normal are for Java, that's the rule of the thumb in Play 2.+

    PostScriptum: Just realized that in your build.sbt you have play.Project.playScalaSettings and actually it should be play.Project.playJavaSettings, this change fixes your problems with Activator.

提交回复
热议问题