我有一些代码可以访问对象属性 datacenter.getId(),该属性是 Long 类型。
问题出在另一段代码中。 遵循新的代码。
<tbody>
@for(datacenter <- datacenterList){
@for(rack <- datacenter.getRacks()){
@for(host <- rack.getHosts()){
<tr>
<td>
@host.getId()
</td>
<td>
@host.getName()
</td>
<td>
@host.getDescription()
</td>
<td>
@rack.getName()
</td>
<td>
@host.getHeightInRackUnits()
</td>
<td>
@host.getEstimatedSizeInTB()
</td>
<td>
<a id = "delete-host" class="delete" href="@routes.InfrastructureController.deleteHost(host.getId())" >
<i class="fa fa-trash-o" style="font-size: 1.3em;"style="font-size: 1.3em;" title="Excluir" data-toggle="modal" data-target="#confirm-modal" data-placement="top" rel="tooltip"></i></a>
</td>
</tr>
}
}
}
</tbody>
遵循路线:
DELETE /hosts/:id controllers.InfrastructureController.deleteHost(id:Long)
控制器方法:
public Result deleteHost(Long id) {
return null;
}
我收到以下错误:
[error] 2016-12-12 11:53:13 -0300 admin - Um erro aconteceu no servidor
java.lang.NullPointerException: null
at scala.Predef$.Long2long(Predef.scala:358)
at views.html.infrastructure.infrastructure_Scope0$infrastructure$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(infrastructure.template.scala:204)
at views.html.infrastructure.infrastructure_Scope0$infrastructure$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(infrastructure.template.scala:180)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.Iterator$class.foreach(Iterator.scala:742)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1194)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
我已经发现错误了。 该对象的 id 参数为 null。 抱歉并感谢您试图帮助我。
您需要从
deleteDatacenter
方法返回实际结果。尝试一下
public Result deleteDatacenter(Long id) {
return Results.ok();
}