NoClassDefFoundError on an interface, not a class

前端 未结 6 775
-上瘾入骨i
-上瘾入骨i 2020-12-21 00:05

I have an issue with NoClassDefFoundError. I am using interfaces, and no class definition should be available:

package code;
public interface Co         


        
6条回答
  •  悲&欢浪女
    2020-12-21 00:55

    Note that there are two different exceptions that sound very similar: ClassNotFoundException and NoClassDefFoundError.

    The first exception occurs in the simple case that the JVM looks for "packageB.ClassA" and can't find it in the search path. There are a few other cases, I suspect, but fairly rare.

    The second exception occurs mostly when an appropriately-named class file is found, but for some reason it can't be used. There are two primary reasons for this:

    1. The class is in, eg, "packageA/ClassA.class" but internally is named "packageB/ClassA" (or the package name was accidentally omitted in the source, or the class file is in the wrong directory, given its package name).
    2. While loading the class, there was some sort of error, usually an error initializing static storage.

提交回复
热议问题