Natanael
Natanael

Reputation: 389

Java NullPointerException in Scala Template

I have a bit of code on which I access a object attribute, datacenter.getId(), this attribute is a Long type.

@edit

The problem is in another piece of code. Follows the new piece of code.

<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>

Follows the route:

DELETE      /hosts/:id                   controllers.InfrastructureController.deleteHost(id:Long)

Controller method:

public Result deleteHost(Long id) {
    return null;
}

And I'm getting the following error:

[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)

Problema solved

I already have found the error. The object was with the id param null. Sorry and thanks for you who tried to help me.

Upvotes: 0

Views: 194

Answers (1)

Shem
Shem

Reputation: 565

You need to return an actual result from deleteDatacenter method. Try

public Result deleteDatacenter(Long id) {
    return Results.ok();
}

It will generate a 200 OK simple result.

Upvotes: 0

Related Questions