• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Runtime error - help!

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I am trying to run a simple program using JDK 1.2 and it is throwing a runtime exception as mentioned below:
Exception in thread "main" java.lang.NoSuchMethodError: main
This is a very simple program which is trying to display a message. Here is the code:
Note : this program compiles successfully.
import javax.swing.JApplet;
import java.awt.Graphics;
import java.applet.*;
public class Showsomemsg extends JApplet
{
public void paint( Graphics g )
{
g.drawString( "Welcome", 25, 25 );
}
}
This program works perfectly when run in a IDEs like JBuilder or IBM Visual Age for JAVA. Only when i try to run from MS-DOS, it throws the above exception.
I had to set the Classpath to point to the location of classes.zip, in the autoexec.bat file. In the classpath, i also have dir. locations pointing to the classes.zip files of the IDE's that I am using(JBuilder and Visual Age). Is this a problem? Can anyone suggest?
Thanks,
- Suresh

 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This doesn't have anything to do with certification, so I'm moving it to Java in General (Beginner).
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a guess, perhaps it means that there is no "main" method in your program. When run from the command line, Java looks in the class you tell it to run and expects to find a method declaration like this:
<code><pre> public static void main(String[] args) {
}</pre></code>
"args" can be any name you want, but the rest is pretty much required. In the main method, you need to tell the JVM what you want it to do. In this case it's probably "display my applet dammit!" , so...
<code><pre> public static void main(String[] args) {
Showsomemesg ssm = new Showsomemesg();
ssm.setVisible(true);
// possibly also tell is what size you want,
// or set other properties
}</pre></code>
Enjoy!
[This message has been edited by Jim Yingst (edited February 11, 2000).]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!