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

Avi Turner

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 Error
error: method render in class index cannot be applied to given types;

My code is (the relevant parts):

MainController.java:

final static Form<Task> taskForm = Form.form(Task.class);

public static Result tasks() {
    return ok(
            views.html.index.render(Task.all(), taskForm)
    );
}

index.sacala.html:

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

I looked around, the closest thread I found was this one, but I was not able to resolve the issue using it (might be due to lack of understanding of the environment / framework...).

One last thing that is worth mentioning:
If I change 'index.sacala.html' to be parameter-less (and change the 'MainController' accordingly, everything works perfectly.

Would appreciate any thoughts about resolving this compilation error.

EDIT:
The Task.all() code is:

public static List<Task> all() {
    return new ArrayList<Task>();
}
biesior

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<Task>,play.api.data.Form<Task>
[error]   found: List<Task>,play.data.Form<Task>
[error]   reason: actual argument play.data.Form<Task> cannot be converted to play.api.data.Form<Task> by method invocation conversion
[error] 1 error

especially these lines:

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

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Play Framework @routes.Assets.at Compilation Error

From Dev

Compilation error following Play! Framework NewApplication guide

From Dev

Objectify with Play Framework 2

From Dev

Error loading large JSON files using Scala Play Framework 2

From Dev

Play Framework Task Example H2 Error - Fixed

From Dev

Play 2.x framework Deploy on Heroku application error

From Dev

Play Framework For Scala: Compilation error[type Application is not a member of package controllers]

From Dev

Play Framework beginner. Scala.html error in compilation

From Dev

Configure QueryDSL on Play 2 Framework

From Dev

Play Framework 2 view declaration

From Dev

Use MongoDB with Play 2 Framework

From Dev

Configure QueryDSL on Play 2 Framework

From Dev

Play 2! framework multithreading issue

From Dev

Play framework compilation issues with dependencies

From Dev

Play Framework 2 & AngularJS - Partial Handling

From Dev

Unit Test controllers in Play 2 framework with Scala

From Dev

How to reference to the standard ActorSystem of play framework 2?

From Dev

Redirect with URL fragment with Play framework 2

From Dev

Loading an arbitrary file in the Play Framework 2 (Scala)

From Dev

How to combine play framework and angular2?

From Dev

Facebook auth plugin for play framework 2

From Dev

Logging syntax for Play Framework 2 in Scala

From Dev

JMX with Play 2.XX framework

From Dev

Slick 2: Delete row in slick with play framework

From Dev

Play Framework 2 Language Code in URL Concept?

From Dev

Play Framework 2 - Different views for different devices

From Dev

How to install RestFB plugin in Play Framework 2

From Dev

Long dynamic routes in play framework 2

From Dev

Setup of a load balancer of 2 play framework instances

Related Related

  1. 1

    Play Framework @routes.Assets.at Compilation Error

  2. 2

    Compilation error following Play! Framework NewApplication guide

  3. 3

    Objectify with Play Framework 2

  4. 4

    Error loading large JSON files using Scala Play Framework 2

  5. 5

    Play Framework Task Example H2 Error - Fixed

  6. 6

    Play 2.x framework Deploy on Heroku application error

  7. 7

    Play Framework For Scala: Compilation error[type Application is not a member of package controllers]

  8. 8

    Play Framework beginner. Scala.html error in compilation

  9. 9

    Configure QueryDSL on Play 2 Framework

  10. 10

    Play Framework 2 view declaration

  11. 11

    Use MongoDB with Play 2 Framework

  12. 12

    Configure QueryDSL on Play 2 Framework

  13. 13

    Play 2! framework multithreading issue

  14. 14

    Play framework compilation issues with dependencies

  15. 15

    Play Framework 2 & AngularJS - Partial Handling

  16. 16

    Unit Test controllers in Play 2 framework with Scala

  17. 17

    How to reference to the standard ActorSystem of play framework 2?

  18. 18

    Redirect with URL fragment with Play framework 2

  19. 19

    Loading an arbitrary file in the Play Framework 2 (Scala)

  20. 20

    How to combine play framework and angular2?

  21. 21

    Facebook auth plugin for play framework 2

  22. 22

    Logging syntax for Play Framework 2 in Scala

  23. 23

    JMX with Play 2.XX framework

  24. 24

    Slick 2: Delete row in slick with play framework

  25. 25

    Play Framework 2 Language Code in URL Concept?

  26. 26

    Play Framework 2 - Different views for different devices

  27. 27

    How to install RestFB plugin in Play Framework 2

  28. 28

    Long dynamic routes in play framework 2

  29. 29

    Setup of a load balancer of 2 play framework instances

HotTag

Archive