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

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.