Unfathomably Easy Java Question

noobman

[H]ard|Gawd
Joined
Oct 15, 2005
Messages
1,475
Hey,

I'm trying to create a ridiculously simple class to recreate an error I'm having with some larger software.

Code:
class TestThisOS
{
    public static void main(String args[]) 
    {
	String whatIsThisOS = System.getProperty("os.name");
        System.out.println("OS: " + whatIsThisOS);
    }
}
The file is called TestThisOS.java
When I run "javac TestThisOS.java", the file compiles to a class successfully.
However, when I attempt to run the class from the command line, I receive the following error:

Code:
Exception in thread "main" java.lang.NoCLassDefFoundError: TestThisOS.class
Caused by: java.lang.ClassNotFoundException: TestThisOS.class

...bla bla bla
Any ideas? I find it odd, because my %PATH% environment variable in Windows is configured and working.
 
What package is the class in and what is the command line you are using to run it.
 
It's not a public class. If it's got a main method that you want to run from scratch, it's gotta be a public class. NoClassDefFoundError means it can't find the right class.
 
It's not a public class. If it's got a main method that you want to run from scratch, it's gotta be a public class. NoClassDefFoundError means it can't find the right class.

That is incorrect. You directly execute a default access class if it has a main method. It certainly isn't best practices though.
 
lol, i know what you're doing wrong. classic mistake:

Code:
fluxion@purity:~/temp$ cat TestThisOS.java 
class TestThisOS
{
    public static void main(String args[]) 
    {
		String whatIsThisOS = System.getProperty("os.name");
        System.out.println("OS: " + whatIsThisOS);
   }
}
fluxion@purity:~/temp$ javac TestThisOS.java 
fluxion@purity:~/temp$ java TestThisOS 
OS: Linux
fluxion@purity:~/temp$ java TestThisOS.class
Exception in thread "main" java.lang.NoClassDefFoundError: TestThisOS/class
Caused by: java.lang.ClassNotFoundException: TestThisOS.class
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
fluxion@purity:~/temp$
 
Back
Top