Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

A Basic Simple Problem  RSS feed

 
Gary Farms
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a simple "Hello World " java program. It looks as follows:
public class Welcome
{
public static void main String args[] )
{
System.out.println("Hello World!" );
}
}
It compiles OK, but when I attempt to run it, I get an error stating:
"Exception in thread "main" java.lang.NosuchMethodError: main
Why am I getting this error??
 
Julia Reynolds
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is probably a classpath problem. On the command line before you type java HelloWorld, set the classpath to include the current directory like this:
set classpath=%classpath%;.
Don't leave out the dot at the end, that is the current directory symbol.
Julia
 
sachin vyahalkar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check your classpath of java library and bin.
It should be set as
PATH = c:\jdk1.3\bin;
SET CLASSPATH = C:\jdk1.3\lib;
SET JAVA_HOME = C:\jdk1.3;
 
vikinsa
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!,
There is an error in your program...
public class Welcome
{
public static void main String args[] )
{
System.out.println("Hello World!" );
}
}

Should be

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

You have forgot "(String[] args)"
Originally posted by Gary Farms:
I wrote a simple "Hello World " java program. It looks as follows:
public class Welcome
{
public static void main String args[] )
{
System.out.println("Hello World!" );
}
}
It compiles OK, but when I attempt to run it, I get an error stating:
"Exception in thread "main" java.lang.NosuchMethodError: main
Why am I getting this error??


------------------
Vikas Aggarwal
Technology Associate
http://www.vikinsa.com
 
Johannes de Jong
tumbleweed
Bartender
Posts: 5089
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vikinsa as much as I appreciate you unselfish help, your user name does not comply with the JavaRanch's naming policy. Pse change it you wish to continue posting in our forums.
Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!