#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    1

    Cmd java run issue


    When I compile my java application in NetBeans there's no problem but when I try to run my application through the command prompt I get the following error:

    Exception in thread "main" java.lang.NoClassDefFoundError: CarInsuranceCalc (wrong name: pkgCarInsuranceCalc/CarInsuranceCalc)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Exception in thread "main" java.lang.NoClassDefFoundError: CarInsuranceCalc (wrong name: pkgCarInsuranceCalc/CarInsuranceCalc)
    You left off the commandline showing what command you entered. I assume it was:
    java CarInsuranceCalc

    However the class is in a package: pkgCarInsuranceCalc
    The full name of the class includes the package name so the commandline should be:
    java pkgCarInsuranceCalc.CarInsuranceCalc
    and that command must be issued in the folder containing the pkgCarInsuranceCalc folder, not in the pkgCarInsuranceCalc folder where the .class file is.

    Comments on this post

    • 0w1 agrees : Thank you
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    1
    Originally Posted by NormR
    You left off the commandline showing what command you entered. I assume it was:
    java CarInsuranceCalc

    However the class is in a package: pkgCarInsuranceCalc
    The full name of the class includes the package name so the commandline should be:
    java pkgCarInsuranceCalc.CarInsuranceCalc
    and that command must be issued in the folder containing the pkgCarInsuranceCalc folder, not in the pkgCarInsuranceCalc folder where the .class file is.
    Thanks, that seemed to solve the error I was having but now I'm getting the following error:
    Error: Could not find or load main class pkgCarInsuranceCalc.CarInsuranceCalc.class

    (Actually doesn't matter tried the latest command in the src folder and it worked).
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Again you did not post the commandline so I have to guess.

    The .class is NOT part of the classname. Remove it.

IMN logo majestic logo threadwatch logo seochat tools logo