• Post Reply Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError  RSS feed

 
Kamil Hlubek
Ranch Hand
Posts: 49
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I wrote code for myself, as suddenly something strange happened, I got the NoClassDefFound-Error, because the name of a class is false. Here ist the code snippet and the error message from the command line:



This code is int the file "Test.java" and if I execute it with javac and java I get this error from the command line:

  • C:\Users\Kamil\Desktop>javac Test.java

    C:\Users\Kamil\Desktop>java Test
    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" java.lang.NoClassDefFoundError: test (wrong name: Tes
    t)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.privateGetMethodRecursive(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

    C:\Users\Kamil\Desktop>


  • But if I change only the identifier of the used interface from test to est for example, the code fully compiles and execute:

  • C:\Users\Kamil\Desktop>javac Test.java

    C:\Users\Kamil\Desktop>java Test
    Class1
    Class2

    C:\Users\Kamil\Desktop>


  • So why this error is comming up, when Java is case-sensitive?

    My guess is, that in the JLS is a bottom line and I do not know anything of it, so I would be happy if someone could explain my the previusly mentioned behavior.

    Thank you for your help,

    Kamil



     
    Liutauras Vilda
    Marshal
    Posts: 4805
    330
    BSD
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    After you compile such a source file, how many class files you get in your folder? and how these are named?
    Surely problem should be with interface name "test" and your main class "Test".
     
    Campbell Ritchie
    Marshal
    Posts: 56221
    171
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Make yourself a java folder somewhere rather than putting all your work on the desktop.
    mkdir java
    cd java

    I made a directory to hold your code and compiled it and ran it and there were no Exceptions or Errors. Please use the dir command to see whether you have the following four files in the same directory, as Liutauras has already suggested:-
    test.class Class1.class Class2.class Test.class
     
    Campbell Ritchie
    Marshal
    Posts: 56221
    171
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Also see whether there is anything else called test.
     
    Kamil Hlubek
    Ranch Hand
    Posts: 49
    2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator


    Yes, I actually noticed the compiler does not create the Test.class file, but I forgot to write it in my question.

    I compiled the code in a new folder ( you can see the result in the picture above ), but it is the same. I read not long ago, that NoClassDefFoundError has some more point, why it can occur, but if the error does not occur in your testing it is a little thing to thing about.
     
    Kamil Hlubek
    Ranch Hand
    Posts: 49
    2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Now I know, that it is clearly about the relation of the identifiers Test and test, because this result( the code a the bottom of this reply ) is a completly different error, but if I change only the identifier of the interface or of the class, It works.

    Code:



    Error:

    Fehler: Hauptklasse Test konnte nicht gefunden oder geladen werden ( this is german and means, that the main class Test could not be found or loaded )


    I look forward to the replies of your.



     
    Campbell Ritchie
    Marshal
    Posts: 56221
    171
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Stop changing the code. You have code which ought to work; it ran first time when I tried it. You need to find what went wrong, not try guessing.
    Please post the text of the list of files using this copying technique; your picture is difficult to read. You need to know which .class files are in your folder, not a repeat of the error messages which you have already posted correctly.
    Can you run any other Java® code? Do you get error messages about checking your installation with anything else?
     
    Liutauras Vilda
    Marshal
    Posts: 4805
    330
    BSD
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Kamil Hlubek wrote:I look forward to the replies of your.
    I think your question were answered already. When you name your classes/interfaces in the same name (not necessarily test), one overrides the other, so you end up with one class file instead of two.
    It is ironic though, when you're trying to test your code, AND naming your classes and interfaces as test - your all tests ends up because of poorly chosen the same name.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!