I have Exception in thread "main" java.lang.NoClassDefFoundError: A (wrong name: a)
and I dont't have any idea what this can caused by
public class Test
{
public static void main(String[] args)
{
new B();
}
}
interface a { }
class A implements a { }
class B extends A { }
Edit: in online compiler https://www.onlinegdb.com/online_java_compiler it compiles
When Java compiles your source code, it creates multiple .class
files. For example, it creates Test.class
for public class Test
, a.class
for interface a
, and A.class
for class A
. The problem here is that file names in some operating systems are case-insensitive. This means that the operating system sees a.class
and A.class
as the same file so one will overwrite the other.
The online compiler most likely treats these file names as different due to case-sensitivity.
The solution here is to use different names so that you avoid these name collisions at the operating system level.
The established Java convention is to start all class and interface names with an upper case letter. If you follow this convention, then you will avoid this problem.
If you run javac
path/to/your/file
, you should see the list of .class
files created by the java compiler in that dir. The problem with your approach is you have duplicate names for the interface and the class i.e A (case insensitive) and as a result only one .class
gets created. Try again by changing the name of either interface or class and your problem should go away.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With