Java gives an error on everything

Soldato
Joined
27 Oct 2005
Posts
13,804
Location
Netherlands
Hello,

Can anyone help me get java working on my pc, I use this bit of code:
Code:
class priem
{
	public static void main(String[] args)
	{
				System.out.println("hello world");
		
	}
}
saved as priem.java
I compile it and it creates the .class.
I type in java priem.
And the command prompt returns this:

Code:
Exception in thread "main" java.lang.NoClassDefFoundError: priem
Caused by: java.lang.ClassNotFoundException: priem
        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:303)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
Could not find the main class: priem.  Program will exit.



It gives the same error, not being able to find the clas, on any java file, the same bytecode works fine on another pc...
 
Last edited:
***disclaimer** never looked at java before in my life ***

I would try putting public before the class definition, if it's anything like .NET all classes are private by default.
 
Same problem, the problem is not the code, the problem is that it gives that error on things that do work on otehr pc's.
 
You have a classpath error. Although you managed to compile the source code (.java) to bytecode (.class) the Java VM executable (java.exe or javaw.exe) does not know where the class you just compiled is, it's not in any of it's known classpaths.

This is down to the machine configuration, hence why it works on some machines, you can use a command line option to explicitly tell the Java VM executable where to look for classes.

Try this:

Code:
[SIZE="4"][B]java -classpath . priem[/B][/SIZE]

If it works type in the following command and paste the output in this thread.

Code:
[SIZE="4"][B]echo %CLASSPATH%[/B][/SIZE]
 
Last edited:
Aye that works...

It says this:
Code:
C:\Program Files (x86)\Java\jdk1.6.0_17\bin;C:\Program Files (x86)\Java\jdk1.6.0
_17\lib
 
I can see the problem, your classpath is missing '.' which is a reference to the working directory so you need to add it in. Open a command prompt and type in:

Code:
[B][SIZE="4"]SET CLASSPATH=%CLASSPATH%;.[/SIZE][/B]

Make sure you don't put in any extra spaces.

If you then echo the classpath again you should see:

C:\Program Files (x86)\Java\jdk1.6.0_17\bin;C:\Program Files (x86)\Java\jdk1.6.0_17\lib;.
 
Sometimes you cannot change it from the command prompt, it might not save your changes so here is another way.

Press [Windows Key] + Pause/Break to bring up the System Properties window.

On Vista/Windows 7 click the 'Advanced system settings' button.

Go to the 'Advanced' tab and click on 'Environment Variables'

From this window you can manually change the CLASSPATH variable to include ;.
 
Last edited:
Ah k, thanks, so I messed up with my classpath ( I did it myself)...
Ty for your help, now to catch up with 3 weeks worth of programming coursework :D.
 
Back
Top Bottom