使用java和ebean的play 2框架进行数据管理。我的下拉列表有问题。下拉列表中填充了来自mySQL数据库的数据。它工作但看起来我不小心改变了一些东西,现在它在我尝试渲染页面时给了我一个空指针异常。 我试图解决问题,但看起来无法解决问题。我提供下面的代码片段。
这是填充下拉列表的代码:
public static Result gestureNames()
{
List <GestureClassEntity> gcet = GestureClassEntity.find.orderBy("name asc").findList();
return ok(views.html.train.render(gcet));
}
这是该方法的路由配置:
GET /name controllers.Application.gestureNames()
这是更新路由文件:
# Home page
GET / controllers.Application.index()
GET /socket controllers.Application.webSocket()
GET /cobject controllers.Application.classifyObject()
GET /classify controllers.Application.classify()
GET /name controllers.Application.gestureNames()
GET /train controllers.Application.train()
GET /tclassifier controllers.Application.trainClassifier()
这些是火车和手势名方法
public static Result train()
{
return ok(train.render(null));
}
public static Result gestureNames()
{
List <GestureClassEntity> gcet = GestureClassEntity.find.orderBy("name asc").findList();
return ok(views.html.train.render(gcet));
}
这是scala.html文件中的参数定义
@( gestureList: List[GestureClassEntity])
这是下拉列表的代码:
<select class = "selectone">
@for(gesture <- gestureList){
<option value = @gesture.id>
@gesture.getName()
</option>
}
</select>
运行scala.html文件时出现零点异常。
这是堆栈跟踪:
[error] application -
! @6bjof8n9g - Internal server error, for request [GET /train] ->
play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[NullPo
interException: null]]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [
play_2.9.1.jar:2.0.2]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [
play_2.9.1.jar:2.0.2]
at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.
2]
at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.
2]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.j
ar:2.0.2]
Caused by: java.lang.NullPointerException: null
at scala.collection.JavaConversions$JListWrapper.iterator(JavaConversion
s.scala:618) ~[scala-library.jar:0.11.3]
at scala.collection.IterableLike$class.foreach(IterableLike.scala:73) ~[
scala-library.jar:0.11.3]
at scala.collection.JavaConversions$JListWrapper.foreach(JavaConversions
.scala:615) ~[scala-library.jar:0.11.3]
at scala.collection.TraversableLike$class.map(TraversableLike.scala:194)
~[scala-library.jar:0.11.3]
at scala.collection.JavaConversions$JListWrapper.map(JavaConversions.sca
la:615) ~[scala-library.jar:0.11.3]
at views.html.train$.apply(train.template.scala:50) ~[classes/:na]
任何人都可以帮我解决这个问题因为我必须将项目作为作业提交,而且我迟到了。
谢谢大家。
答案 0 :(得分:2)
问题来自/train
Url的调用,因为它映射到train()
方法,该方法使用GestureClassEntity
的列表调用模板,该列表为null:
GET /train controllers.Application.train()
然后它调用:
public static Result train()
{
return ok(train.render(null)); // <- here is the problem
}