java.lang.NoClassDefFoundError - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

java.lang.NoClassDefFoundError

RaisonRaison Posts: 24Member
Hi, this is probably common problem. But i am quite sure i have the correct procedures. Yet i cant solve this problem: My java program compiles but just cant run under command prompt. It can run under my IDE though which is jCreator.

[b]CLASSPATH = .;C:j2sdk1.4.2_04jrelibext;C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt filesjava workspaceschool lablab2;C:j2sdk1.4.2_04jrelib;"iQTJava.zip"
[/b]

[code]
Directory of C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt fi
lesjava workspaceSchool LabLab2ClientClasses

[.] [..] TestFrog.class TestFrog.java
2 File(s) 707 bytes
2 Dir(s) 33,909,579,776 bytes free

C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt filesjava works
paceSchool LabLab2ClientClasses>java testfrog
Exception in thread "main" java.lang.NoClassDefFoundError: testfrog (wrong name:
ClientClasses/TestFrog)
at java.lang.ClassLoader.defineClass0(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.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.ClassLoader.loadClassInternal(Unknown Source)
[/code]

TESTFROG.java

[code]
package ClientClasses;

import SCLab.*;

public class TestFrog {

/**
* Method main
*
*
* @param args
*
*/
public static void main(String args[]) {
Frog jeremy = new Frog();
for(int i = 0;i<5;i++) jeremy.grow();
}

/**
* Method TestFrog
*
*
*/
public TestFrog() {
// TODO: Add your code here
}
}
[/code]

Directory structure of my files
[code]
Directory of C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt fi
lesjava workspaceSchool LabLab2

[.] [..] [ClientClasses] Lab2.jcp Lab2.jcu
Lab2.jcw [SCLab] src_lab2.txt
4 File(s) 1,853 bytes
4 Dir(s) 33,909,379,072 bytes free

C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt filesjava works
paceSchool LabLab2>cd sclab

C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt filesjava works
paceSchool LabLab2SCLab>dir/w
Volume in drive C has no label.
Volume Serial Number is 341F-4EBD

Directory of C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt fi
lesjava workspaceSchool LabLab2SCLab

[.] [..] AdultStage.class
AdultStage.java DeadStage.class DeadStage.java
Frog.class Frog.java GrowingStage.class
GrowingStage.java TadpoleStage.class TadpoleStage.java
10 File(s) 5,097 bytes
2 Dir(s) 33,909,379,072 bytes free
[/code]

Comments

  • beancounterbeancounter Posts: 88Member
    :
    Hi;

    At the command prompt try typing java TestFrog instead of java testfrog.

    Hope this helps

    Ken

    Hi, this is probably common problem. But i am quite sure i have the correct procedures. Yet i cant solve this problem: My java program compiles but just cant run under command prompt. It can run under my IDE though which is jCreator.
    :
    : [b]CLASSPATH = .;C:j2sdk1.4.2_04jrelibext;C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt filesjava workspaceschool lablab2;C:j2sdk1.4.2_04jrelib;"iQTJava.zip"
    : [/b]
    :
    : [code]
    : Directory of C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt fi
    : lesjava workspaceSchool LabLab2ClientClasses
    :
    : [.] [..] TestFrog.class TestFrog.java
    : 2 File(s) 707 bytes
    : 2 Dir(s) 33,909,579,776 bytes free
    :
    : C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt filesjava works
    : paceSchool LabLab2ClientClasses>java testfrog
    : Exception in thread "main" java.lang.NoClassDefFoundError: testfrog (wrong name:
    : ClientClasses/TestFrog)
    : at java.lang.ClassLoader.defineClass0(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.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.ClassLoader.loadClassInternal(Unknown Source)
    : [/code]
    :
    : TESTFROG.java
    :
    : [code]
    : package ClientClasses;
    :
    : import SCLab.*;
    :
    : public class TestFrog {
    :
    : /**
    : * Method main
    : *
    : *
    : * @param args
    : *
    : */
    : public static void main(String args[]) {
    : Frog jeremy = new Frog();
    : for(int i = 0;i<5;i++) jeremy.grow();
    : }
    :
    : /**
    : * Method TestFrog
    : *
    : *
    : */
    : public TestFrog() {
    : // TODO: Add your code here
    : }
    : }
    : [/code]
    :
    : Directory structure of my files
    : [code]
    : Directory of C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt fi
    : lesjava workspaceSchool LabLab2
    :
    : [.] [..] [ClientClasses] Lab2.jcp Lab2.jcu
    : Lab2.jcw [SCLab] src_lab2.txt
    : 4 File(s) 1,853 bytes
    : 4 Dir(s) 33,909,379,072 bytes free
    :
    : C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt filesjava works
    : paceSchool LabLab2>cd sclab
    :
    : C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt filesjava works
    : paceSchool LabLab2SCLab>dir/w
    : Volume in drive C has no label.
    : Volume Serial Number is 341F-4EBD
    :
    : Directory of C:Documents and SettingsEdmundMy DocumentsMy eBooksMy expt fi
    : lesjava workspaceSchool LabLab2SCLab
    :
    : [.] [..] AdultStage.class
    : AdultStage.java DeadStage.class DeadStage.java
    : Frog.class Frog.java GrowingStage.class
    : GrowingStage.java TadpoleStage.class TadpoleStage.java
    : 10 File(s) 5,097 bytes
    : 2 Dir(s) 33,909,379,072 bytes free
    : [/code]
    :
    :

  • RaisonRaison Posts: 24Member
    [b][red]This message was edited by Raison at 2004-8-14 7:15:20[/red][/b][hr]
    Hi, I am very close to solving the problem.

    My program finally worked if "TestFrog.java" is not packaged into ClientClasses and i run it in the ClientClasses directory.

    Or i can keep the file packed in the package ClientClasses. I have to run it by specifying the whole package name even in the ClientClasses directory itself, i.e "java ClientClasses.TestFrog"

    Therefore,i conjecture that even if i specify the classpath to include the current directory using '.', the class will not be visible if it is packed in a package unless you specify whole package name.

    Really hope someone can enlighten me about this. Thanks!



Sign In or Register to comment.