没有参数允许使用nullary方法:()play.twirl.api.HtmlFormat.Appendable in object main

时间:2018-05-02 17:34:28

标签: playframework

1@()
2
3@main("breakfast") { 
4<h1 class="text-center">Breakfast recipes</h1>
5
6<div class="alt-prg row">
7    <div class="col-md-4 col-sm-12">

有没有人遇到过这个错误。一切正常,现在它不会编译

  

main.scala

@(title: String)(content: Html)

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Online Shop - @title</title>

<!-- Bootstrap Core CSS -->
<link rel="stylesheet" 
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" 
integrity="sha384- 
Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" 
crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Open+Sans" 
rel="stylesheet">

<!-- Custom CSS -->
<link href="@routes.Assets.versioned("stylesheets/main.css")" 
rel="stylesheet" />

</head>

我现在添加了main.scala文件,看看我是否有明显的错误。

来自breakfast.scala文件的代码

@()

@main("breakfast") {
<h1 class="text-center">Breakfast recipes</h1>

<div class="alt-prg row">
<div class="col-md-4 col-sm-12">
    <div class="rowImage"><img 
src="@routes.Assets.versioned("images/spotato.jpg")" alt="Alternate Text" /> 
</div>
</div>
<div class="col-md-8 col-sm-12  text-right">
    <h4>Sweet potato, Egg & Turkey Bacon</h4>
    <p>
        Lorem ipsum dolor sit amet, eum diceret vivendo ne, ei
        harum prompta tacimates mel. Te eum solet graeco maluisset,
        ius id malorum voluptatum. Mei vero suavitate ad, quo paulo 
        suavitate te.
        Eum id vidit deleniti appetere, modo stet dissentiet no usu. Ad his 
         clita debitis
        splendide, eleifend adversarium an eam, ea usu singulis omittantur
    </p>
    <a class="btn btn-primary" href="@routes.Assets.versioned("recipes/Sweet 
        Potatoe,Egg _ Turkey Bacon.docx")">Download Recipe</a>
</div>
</div>

你能看到任何可能引起问题的事吗?

1 个答案:

答案 0 :(得分:1)

通常,编译错误no arguments allowed for nullary method apply表示我们正在将参数传递给apply方法,该方法不接受任何参数。例如,以下

object A {
  def apply(): String = ""
}

A(3) // compiler sees this as A.apply(3)

给出了编译错误

no arguments allowed for nullary method apply: ()String in object A

在您的情况下,类似的错误

no arguments allowed for nullary method apply: ()play.twirl.api.HtmlFormat.Appendable in object main

似乎表明存在具有以下签名

的Twirl模板main.scala.html
@()

<html>
...
</html>

将Twirl转换为类似于

main对象
object main extends BaseScalaTemplate {
  def apply(): play.twirl.api.HtmlFormat.Appendable = {
    ...
  }
}

并且正在从其他地方调用,例如控制器或其他Twirl模板,其参数错误地传递给其apply方法。例如,如果我们index.scala.html调用main就像这样

@()

@main("breakfast")

然后我们得到你的编译错误

[error] example/app/views/index.scala.html:3: no arguments allowed for nullary method apply: ()play.twirl.api.HtmlFormat.Appendable in object main
[error] @main("breakfast")