Does anyone know how to fix this error?

1,171 views
Skip to first unread message

Justin Holmes

unread,
Nov 16, 2011, 8:14:31 AM11/16/11
to mor...@googlegroups.com
java.lang.IllegalArgumentException: can't parse argument number interface com.google.code.morphia.annotations.Id=@com.google.code.morphia.annotations.Id()

stack trace
java.lang.ExceptionInInitializerError: null
        at java.lang.Class.forName0(Native Method) ~[na:1.6.0_29]
        at java.lang.Class.forName(Class.java:169) ~[na:1.6.0_29]
        at com.google.code.morphia.utils.ReflectionUtils.getFromDirectory(ReflectionUtils.java:507) ~[morphia-0.99.1-SNAPSHOT.jar:na]
        at com.google.code.morphia.utils.ReflectionUtils.getClasses(ReflectionUtils.java:580) ~[morphia-0.99.1-SNAPSHOT.jar:na]
        at com.google.code.morphia.utils.ReflectionUtils.getClasses(ReflectionUtils.java:544) ~[morphia-0.99.1-SNAPSHOT.jar:na]
        at com.google.code.morphia.Morphia.mapPackage(Morphia.java:85) ~[morphia-0.99.1-SNAPSHOT.jar:na]
Caused by: java.lang.IllegalArgumentException: can't parse argument number interface com.google.code.morphia.annotations.Id=@com.google.code.morphia.annotations.Id()
        at java.text.MessageFormat.makeFormat(MessageFormat.java:1339) ~[na:1.6.0_29]
        at java.text.MessageFormat.applyPattern(MessageFormat.java:458) ~[na:1.6.0_29]
        at java.text.MessageFormat.<init>(MessageFormat.java:350) ~[na:1.6.0_29]
        at java.text.MessageFormat.format(MessageFormat.java:811) ~[na:1.6.0_29]
        at org.slf4j.bridge.SLF4JBridgeHandler.getMessageI18N(SLF4JBridgeHandler.java:251) ~[jul-to-slf4j.jar:na]
        at org.slf4j.bridge.SLF4JBridgeHandler.callLocationAwareLogger(SLF4JBridgeHandler.java:209) ~[jul-to-slf4j.jar:na]

I have just started updating my applications to Play 2.0, Morphia used to work fine with https://github.com/justinholmes/Scala-Mongo-Morphia-Mapper/blob/master/src/MongoDB.scala but now it also generates this error

NoClassDefFoundError: Could not initialize class models.User$ 


Thanks in advance.

Justin Holmes

Brian Nesbitt

unread,
Nov 26, 2011, 10:37:45 PM11/26/11
to mor...@googlegroups.com
Hi Justin,

I am using Play 2.0 and morphia with Scala as well.  I just came across this yesterday.  I had a standalone application that I was pulling into Play and started seeing this issue.  It revolves around the new logging setup.  Play 2.0 uses sl4j bridge (SLF4JBridgeHandler.install()) and sets up the root logger.

You need to register the sl4j morphia handler as well.  This is explained here:


... and I quickly mention it in a comment on a bug at the following location, but the link above is enough to fix you up.

Justin Holmes

unread,
Nov 27, 2011, 7:11:13 AM11/27/11
to mor...@googlegroups.com
Thanks for that, however I am getting LoggerImplFactory must be registered before logging is initialized. where exactly in my MongoDB Scala Class do I put it because I have tried all the places that seem logical

green

unread,
Nov 27, 2011, 7:30:09 AM11/27/11
to mor...@googlegroups.com
I've met that Exception before. My solution is call MorphiaLoggerFactory.reset() before calling MorphiaLoggerFactory.registerLogger(loggerClazz)

Brian Nesbitt

unread,
Nov 27, 2011, 9:17:05 AM11/27/11
to mor...@googlegroups.com
Where do you call to initiate Morphia?  You can put the code in the body of any class to have it run statically.

I start to initialize stuff in Global.beforeStart() so I put it in the body of that class so it runs "statically".  I tried in the beforeStart() method but I saw the same error you got because the bridge logger had already been setup by Play.

object Global extends GlobalSettings {
  MorphiaLoggerFactory.registerLogger(classOf[SLF4JLogrImplFactory]);

  override def beforeStart(app: Application) {

    MongoDB.init("mynhl").mapPackage("models").indexes

    // more code
  }
}

green

unread,
Nov 27, 2011, 1:55:32 PM11/27/11
to mor...@googlegroups.com
You can find the code at  https://github.com/greenlaw110/play-morphia/blob/master/src/play/modules/morphia/MorphiaPlugin.java , search for "initMorphia_". Note it's for play 1.2.x, haven't got a chance to try play 2.0 yet. 

Justin Holmes

unread,
Nov 28, 2011, 10:43:59 AM11/28/11
to mor...@googlegroups.com
Thanks guys I fixed it with the reset.
Reply all
Reply to author
Forward
0 new messages