简体   繁体   中英

java.lang.NoClassDefFoundError: Could not initialize class play.data.format.Formatters

I'm using Play 2.1.2 and I want to use dynamic forms. I tried it in my own small hello world project and everything worked fine, but when I use forms in other bigger project I'm getting an exception. Here is my code (in both project is the same):

Controller

public static Result signInForm() {
    DynamicForm form = Form.form().bindFromRequest();   //exception on this line
    return renderJapid(form);
}

Routes

GET     /sign-in                                            controllers.Authentication.signInForm()

When I go to localhost:9000/sign-in I get this exception :

Caused by: java.lang.NoClassDefFoundError: Could not initialize class play.data.format.Formatters
at play.data.Form.bind(Form.java:320) ~[play-java_2.10.jar:2.1.2]
at play.data.DynamicForm.bind(DynamicForm.java:100) ~[play-java_2.10.jar:2.1.2]
at play.data.DynamicForm.bindFromRequest(DynamicForm.java:71) ~[play-java_2.10.jar:2.1.2]
at controllers.Authentication.signInForm(Authentication.java:310) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$19$$anonfun$apply$19.apply(routes_routing.scala:305) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$19$$anonfun$apply$19.apply(routes_routing.scala:305) ~[na:na]

Please, can you help me? Where could be the problem? I've checked Global.java and application.conf in both projects but I didn't find anything what could cause this problem.

UPDATE :

I've tried to put this code

FormattingConversionService fcs = Formatters.conversion;

before the line with the dynamic form call. After reloading localhost:9000/sign-in in browser I got this exception on that new line:

Caused by: java.lang.NullPointerException: null
at play.data.format.Formatters.register(Formatters.java:186) ~[play-java_2.10.jar:2.1.2]
at play.data.format.Formatters.<clinit>(Formatters.java:100) ~[play-java_2.10.jar:2.1.2]
at controllers.Authentication.signInForm(Authentication.java:310) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$19$$anonfun$apply$19.apply(routes_routing.scala:305) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$19$$anonfun$apply$19.apply(routes_routing.scala:305) ~[na:na]
at play.core.Router$HandlerInvoker$$anon$6$$anon$2.invocation(Router.scala:175) ~[play_2.10.jar:2.1.2]

So it seems that Formatters is in the classpath. But when I hit the reload button in the browser again I get the same NoClassDefFoundError as before (this time on the line which I added).

NoClassDefFoundError usually means that the class is not on the classpath. Possibly it was there when you compiled it, but now it is missing (seen this with shared libraries mostly).

NoClassDefFoundError documentation

Looks like it is probably not finding play-java_2.10.jar.

EDIT: (to sum up the comments)

The Play jar uses Spring for binding data. Initial thought was Spring was not included on classpath, but it was. However, the Spring on the classpath appears to have a conflict with some Spring jars in the lib folder. Removing the jars in the lib folder seems to have cleared up the error. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM