我正在使用 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