播放框架2.1.1上的渲染模板时的运行时异常

时间:2013-07-06 18:42:30

标签: java akka playframework-2.1

即时使用java play framework 2.1.1

我正在使用InvocationTargetException方法获取invoke。为了了解调用方法中抛出的异常,我创建了此代码:
https://github.com/jstar88/LibreTitan/blob/master/app/controllers/pages/player/Chat.java

//invoked function
public static Result show(User user) {
    try{
        return ok(chatIndex.render(user.skin));
    }
    catch(Exception ex)
    {
        StringWriter errors = new StringWriter();
        ex.printStackTrace(new PrintWriter(errors));
        return ok(errors.toString());
    }
}

我得到了

 java.lang.RuntimeException: There is no HTTP Context available from here.
at play.mvc.Http$Context.current(Http.java:30)
at play.mvc.Http$Context$Implicit.flash(Http.java:167)
at views.html.game.chatIndex$.apply(chatIndex.template.scala:32)
at views.html.game.chatIndex$.render(chatIndex.template.scala:52)
at views.html.game.chatIndex.render(chatIndex.template.scala)
at controllers.pages.player.Chat.show(Chat.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at controllers.Rights.callController(Rights.java:73)
at controllers.Rights.access$000(Rights.java:14)
at controllers.Rights$1.call(Rights.java:32)
at controllers.Rights$1.call(Rights.java:30)
at akka.dispatch.Futures$$anonfun$future$1.apply(Future.scala:75)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:137)
at scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1417)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:262)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)

您可以在此处查看所有代码https://github.com/jstar88/LibreTitan/tree/master/app
也许我在模板中犯了一些逻辑错误?谢谢

编辑:同样的错误也发生在2.1.2

1 个答案:

答案 0 :(得分:0)

从源代码中,您需要模板中的Flash范围。只需在模板的开头添加隐式flash参数:

@(skin: String)(implicit flash: Flash)