0

While debugging our product, I already found a NoClassDefFoundError which is however weird to me- I noticed following output from the class loading log(by turning on -verbose:class):

[Loaded com.xxx.yyy.preferences.PreferencesMgr from file:/C:/Users/xxx/.gradle/caches/zzz.jar

PreferencesMgr is just the class that causes NoClassDefFoundError:

java.lang.NoClassDefFoundError: Could not initialize class com.xxx.yyy.preferences.PreferencesMgr

So it seems that jvm actually has already loaded the class sucessfully. Then why there is a NoClassDefFoundError? What possibilities?

qingjinlyc
  • 175
  • 2
  • 12
  • Maybe some dependencies is missing. Show full log. – talex Sep 21 '17 at 09:13
  • The log is too huge to be posted here. While I go through the log but find no other exceptions. – qingjinlyc Sep 21 '17 at 09:15
  • `NoClassDefFoundError` here could indicate a different class required during initialization of PreferencesMgr. Check initialization sequence of it for some info. – cooltoad Sep 21 '17 at 09:15
  • @qingjinlyc then post whole exception. I think it may contain inner exception (You can see it after "caused by"). – talex Sep 21 '17 at 09:16
  • Also I should mention that if you use custom ClassLoaders it may result in class loaded in one of them and searched in another. – talex Sep 21 '17 at 10:07

2 Answers2

0

Might be a dependency issue, another package might also define a PreferenceMgr Class which causes conflicts. With Gradle, you can use some commands to check the dependencies: Check this post

Arno
  • 305
  • 3
  • 14
0

Things are clear now. PreferenceMgr depends on another jar which has bug in certain version. In gradle, we set the bug version of the jar. Thus when loading PreferenceMgr, classloader trigers the bug in MAUtils and results in NoClassDefFoundError.

qingjinlyc
  • 175
  • 2
  • 12