Sign in to follow this  

Please help with the most basic thing!

This topic is 4337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying this simple little program but it just doesn't want to run. This program compiles, and when i run it gives me message: ------------------------------------------------------------------------ Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld Press any key to continue... ------------------------------------------------------------------------ HelloWorld.java
import javax.swing.*;

public class HelloWorld
{
	public static void main (String []args)
	{
		JOptionPane.showMessageDialog(null, "Hello World");
	}// end main
}


main is right there!!!!... I don't understand thank you

Share this post


Link to post
Share on other sites
I'm no java guru, but is that the full command for JOptionPane? I thought it was something more like
JOptionPane.showMessageDialog(null,"HELLO WORLD", "Title", JOptionPane.INFORMATION_MESSAGE);

Again, i'm not sure that is the problem, but sometimes compilers can be picky - so who knows. It can't hurt to try.

Share this post


Link to post
Share on other sites
Quote:
Original post by DJHoy
make sure your classpath includes the current directory...


java -classpath . HelloWorld


how do I make sure of that. I am using "textpad 4.7.3" by the way

How do I set the "environment variables in windows "?

And actually other programs don't work either, like:
Hello.java

public class Hello
{
public static void main (String [] args)
{
System.out.println ("Hello World");
}
}



Gives the same error

Share this post


Link to post
Share on other sites
Quote:
Original post by snm04
How do I set the "environment variables in windows "?

See step 5 of the Java 2 SDK 1.4.2 Installation Notes for Microsoft Windows [java.sun.com/].

Make sure that the path is actually correct for your system when following the instructions - the example one may not exactly match your own if you have a different version of the SDK or a different install location on your system for example, in which case just pasting in the one in the article wouldn't work properly.

Share this post


Link to post
Share on other sites
You have to specify your entry class. In your second example the class containing main is Hello. So you would have to run:

java Hello

Searching for some simple java tutorials will give you any answers you need.

Share this post


Link to post
Share on other sites
Hit the start button, then click on run, then type in cmd, then hit enter, then go to the directory with Hello.java in it. Then run javac.exe on Hello.java, then run java.exe and give it an argument of Hello, and it WILL run, I guarantee it.

Share this post


Link to post
Share on other sites

This topic is 4337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this