0

I recently moved a project from one machine to another but I am now given an error when attempting to run java files on the new machine. I'm trying to run a java file from part of an Android project in command prompt but I am given an error. The file compiles okay but fails to run. Here is the error I am given;

Exception in thread "main" java.lang.NoClassDefFoundError: ChatServer (
e: edu/UTEP/android/ChatServer)
        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 sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

Any ideas why I am receiving this error?

3
  • How are you running your Java file ? Can you add the command ? Commented Mar 9, 2015 at 11:16
  • I am running Javac ChatServer.java which compiles fine and then Java ChatServer to run and given this error. Commented Mar 9, 2015 at 13:46
  • I just posted my answer, you can do any of those two to resolve the issue Commented Mar 9, 2015 at 15:01

3 Answers 3

1

Your ChatServer is having a package declaration of edu.UTEP.android in the top. So either you need to remove that package declaration recompile your java file again and run it

(or)

you need to create folder structure like this

CurrentDir/edu/UTEP/android/

Keep your java file in android folder and invoke java ChatServer from CurrentDir. Any of these two will solve the issue :-)

For more info on packages, you can refer to my previous answer on a similar issue here

Sign up to request clarification or add additional context in comments.

Comments

0

Make sure that the .jar that provides ChatServer is in your runtime Classpath.

Comments

0

This issue rise when jvm don't file class path. check where u have placed your jar file or lib folder. Move to that directory then run javac and then java . Issue will be resolved.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.