Can’t tell you the exact reason as there can be many a situation when it can occur. But, most possibly it occurs because of the mismatch between the classpaths during compile and run-time.
To deal with this, following two exceptions can come in handy:
-
java.lang.ClassNotFoundException
-
java.lang.NoClassDefFoundError