我正在使用带有 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]
谁能帮我解决这个问题,因为我必须将项目作为作业提交,而且我迟到了。
谢谢你们。