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?

Jens
  • 67,715
  • 15
  • 98
  • 113
Yaz
  • 55
  • 3
  • 10

3 Answers3

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

Community
  • 1
  • 1
Arkantos
  • 6,530
  • 2
  • 16
  • 36
0

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

Rahim Pirbhai
  • 445
  • 1
  • 4
  • 6
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.

Yash Varshney
  • 365
  • 1
  • 5
  • 16