LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   java problem (https://www.linuxquestions.org/questions/linux-software-2/java-problem-670214/)

efus 09-16-2008 03:37 AM

java problem
 
I need to do some java programming, so I installed openJDK.
The code compiles fine, but when I try to run it I get this error:

Code:

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
Could not find the main class: HelloWorld. Program will exit.

I get this error with openjdk and sun jdk?
anyone know how to fix this?

harry2006 09-16-2008 08:28 AM

from the error log it seems u r code is incomplete....some class definiton is missing...have a walk-thur of ur code....must be something missing....if u r stillhaving problem....reply with ur code...lets have a look over ur code..tehn it'll be easy fro nyone so say whats the issue...
was ur installation OK...all jar files added properly to the library...???

armanox 09-16-2008 11:04 PM

Looks like a hello world program. Send me it and I'll look it over - it looks like a problem with the source.

efus 09-17-2008 05:53 AM

I don't think it's the source.
The source looks lige this

Code:


public class HelloWorld {
  public static void main(String[] args) {
   
  }
}

and it still gives the error.
It is only on this system I get the error.
Other java apps run fine so I asume the java installation is ok.

elprawn 09-17-2008 06:00 AM

Add . to your $CLASSPATH.

efus 09-17-2008 02:56 PM

this is my CLASSPATH

Code:

/usr/lib/jvm/java-1.6.0-openjdk/lib:/usr/lib/jvm/java-1.6.0-openjdk/jre/lib:/usr/lib/jvm/java-1.6.0-openjdk/lib:/usr/lib/jvm/java-1.6.0-openjdk/jre/lib
where sould I put the . ?

elprawn 09-17-2008 03:53 PM

Code:

usr/lib/jvm/java-1.6.0-openjdk/lib:/usr/lib/jvm/java-1.6.0-openjdk/jre/lib:/usr/lib/jvm/java-1.6.0-openjdk/lib:/usr/lib/jvm/java-1.6.0-openjdk/jre/lib:.

efus 09-18-2008 03:37 AM

Great! It works now. Thank you!

peeths003 09-18-2008 08:04 AM

This is because the JVM was not able to locate your HelloWorld.class file . if you are in the directory of the class file . and you add a . against the classpath , the jvm adds the current directory path and finds your class name .


All times are GMT -5. The time now is 10:35 AM.