gpt4 book ai didi

java - Play Framework 2.2.1 - 编译错误 : "method render in class index cannot be applied to given types;"

转载 作者:搜寻专家 更新时间:2023-10-31 19:46:13 24 4
gpt4 key购买 nike

我是 Play Framework 的新手,正在尝试从 this 构建待办事项列表手动的。

当我尝试运行该应用程序时出现错误:

Compilation Error
error: method render in class index cannot be applied to given types;

我的代码是(相关部分):

主 Controller .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])

我环顾四周,我发现最近的线程是 this一个,但我无法使用它解决问题(可能是由于缺乏对环境/框架的了解......)。

最后一件事值得一提:
如果我将“index.sacala.html”更改为无参数(并相应地更改“MainController”,一切都会完美无缺。

如果有任何关于解决此编译错误的想法,我们将不胜感激。

编辑:
Task.all() 代码是:

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

最佳答案

很可能你的包裹是 models 而不是 Models 是吗?

顺便说一句,这个包是自动导入的,所以你可以使用:

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

嗯,变化...实际上登录控制台说明一切

[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

尤其是这些行:

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

TBH 我从未测试过 Activator,但它看起来将 play.api.data.Form 导入到 View 中,这对于 Java Controller 是不正确的。解决方案是表单的完整路径:

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

正如评论 *.api.* 中提到的,导入适用于 Scala,普通适用于 Java,这是 Play 2.+ 中的经验法则

PostScriptum: 刚刚意识到在你的 build.sbt 中你有 play.Project.playScalaSettings 实际上它应该是 play .Project.playJavaSettings,此更改解决了 Activator 的问题。

关于java - Play Framework 2.2.1 - 编译错误 : "method render in class index cannot be applied to given types;",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21993442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com