aspose file tools*
The moose likes Beginning Java and the fly likes Help please! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help please!" Watch "Help please!" New topic
Author

Help please!

Pen Ho
Greenhorn

Joined: Feb 08, 2001
Posts: 2
I'm a complete beginner to both java and programming and I'm trying to learn Java from a book. I tried the following 'simple' program:
import javax.swing.JApplet;
import java.awt.Graphics;
public class WelcomeApplet extends JApplet{
public void paint (Graphics g)
{
g.drawString("Welcome to Java!",25,25);
}
}
But it doesn't work!
It compiled ok, but when i went to run it using the command "java WelcomeApplet.class" it gave the error "Exception in thread "main" java.lang.NoClassDefFoundError:WelcomeApplet/Class.
And when i used the command "java WelcomeApplet" it gave the error "Exception in thread "main"
java.lang.NoSuchMethodError:main"
Can anyone help?
Jeff Pickett
Greenhorn

Joined: Feb 04, 2001
Posts: 12
Pen Ho,
You must create an HTML file to load the applet into the appletviewer or web browser to execute the applet. An html file ends with the extension ".html" To execute a Java applet you must provide an HTML text file that indicates which applet the appletviewer (or browser) should load and execut.
Create an html file and call it WelcomeApplet.html".
<html>
<applet code="WelcomeApplet.class" width=300 height=30>
</applet>
</html>
After creating the html text file with the opening and closing html tags. ( <html> </html> ) go back to dos and type: appletviewer WelcomeApplet.html
Your applet should load with no problems aftre doing that. First look in the book that you're using and see if it explains how to execute an applet. It would be unusual if the book is teaching applets for the first time without any explanation on how to execute it.
Later
Pen Ho
Greenhorn

Joined: Feb 08, 2001
Posts: 2
Thanks Jeff
I flicked foward through a couple of pages in the book and found the explanation - I guess next time I should do this first!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help please!