我正在尝试在运行时调用静态函数(Users.dashboard())并且我收到了验证错误异常。 Users类继承CRUD.java并且不接受任何参数。
在Home.index()中:
public class Home extends Controller {
public static void index() {
for (Class<CRUD> clazz : play.Play.classloader
.getAssignableClasses(CRUD.class)) {
Dashboard d;
try {
Method m = clazz.getMethod("dashboard");
if (m != null) {
d = (Dashboard) m.invoke(clazz.newInstance(), new Object[] {});
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
} catch (Exception e) {
}
}
render(dashboards);
}
控制台输出:
@69iahfk3j
Internal Server Error (500) for request GET /home
Oops: VerifyError
An unexpected error occured caused by exception VerifyError: (class: controllers/Home, method: index signature: ()V) Register 1 contains wrong type
play.exceptions.UnexpectedException: Unexpected Error
at play.Invoker$Invocation.onException(Invoker.java:242)
at play.Invoker$Invocation.run(Invoker.java:284)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.VerifyError: (class: controllers/Home, method: index signature: ()V) Register 1 contains wrong type
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getDeclaredMethods(Class.java:1791)
at play.utils.Java.findActionMethod(Java.java:98)
at play.mvc.ActionInvoker.getActionMethod(ActionInvoker.java:602)
at play.mvc.ActionInvoker.resolve(ActionInvoker.java:85)
... 1 more
答案 0 :(得分:1)
控制器中的公共静态方法由Play增强,因此对这些方法的调用可能会有问题。
如果它是一个实用工具方法,你是否用@Util注释了这个方法?
如果你只是想在这种情况下重定向到仪表板,你可以简单地在动作上使用重定向,例如
redirect("Users.dashboard");