• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

NoClassDefFoundError

 
Ranch Hand
Posts: 49
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



     
    Sheriff
    Posts: 8988
    652
    Mac OS X Spring VI Editor BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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".
     
    Marshal
    Posts: 80280
    432
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 80280
    432
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 80280
    432
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Sheriff
    Posts: 8988
    652
    Mac OS X Spring VI Editor BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
    Smokeless wood heat with a rocket mass heater
    https://woodheat.net
    reply
      Bookmark Topic Watch Topic
    • New Topic