View Full Version : Java Applet help

March 16, 2005, 12:09 AM
< //html >
< //body >
<//p >< applet code ="Applet1.class" width=700 height=400>
<///applet ><// /p>
< /body// >
< ////html >

So this is the html code. When I try running it on the browser, I get an "Applet Applet1 notinited" error, and the applet doesn't show up. I have my .class file in the same folder as my .html file. I've tried codebase and archive, but those don't work. I have Java enabled on my browser. Any ideas anyone?

I wouldn't have needed it done straightaway (since I am still working on the applets) hadn't it been for testing purposes.


Edited on, March 16, 2005, 5:09 AM GMT, by AsifTheManRahman.

March 16, 2005, 09:39 AM
You can try this..

<#OBJECT codetype="application/java"
width="700" height="400">

However, if still does not work, then the problem is in the applet itself. May be it needs some parameters?

You can pass parameters this way...

<#OBJECT codetype="application/java"
width="700" height="400">
<#PARAM name="welcome" value="Hello.au|Welcome.au">
Java applet that plays a welcoming sound.


<#APPLET code="Applet1" width="700" height="400">
<#PARAM name="welcome" value="Hello.au|Welcome.au">
Java applet that plays a welcoming sound.

Edited on, March 16, 2005, 2:41 PM GMT, by Rajputro.
Reason: Ignore the # signs

March 16, 2005, 08:24 PM

None of them worked. I tried codebase again, and looks like I don't get the error anymore. However, whereas a grey colored box with a red cross at the top left corner representing the applet used to appear before, nothing appears at all now. I am beginning to wonder whether it's a prolem with my applet by any chance. This is what I have so far:

import java.applet.*;
import java.awt.*;

public abstract class Applet1 extends Applet implements Runnable{
private int radius = 10;
private int x = 5;
private int y = 50;
private Image im;
private Graphics gr;
// init - method is called the first time you enter the HTML site with the applet
public void init() {}

// start - method is called every time you enter the HTML - site with the applet
public void start() {
Thread thread = new Thread(this);
public void play(){
Thread.currentThread().setPriority(Thread.MIN_PRIO RITY);
while (true)
catch (InterruptedException e){
Thread.currentThread().setPriority(Thread.MIN_PRIO RITY);
// stop - method is called if you leave the site with the applet
public void stop() {}

// destroy method is called if you leave the page finally (e. g. closing browser)
public void destroy() {}

/** paint - method allows you to paint into your applet. This method is called e.g. if you move your browser window or if you call repaint() */
public void paint (Graphics ball) {
public void DbBuffer(Graphics bgIm)
if (im == null)
im = createImage(this.getSize().width, this.getSize().height);
gr = im.getGraphics();
gr.fillRect(0,0,this.getSize().width, this.getSize().height);


So this is my .class file....any ideas?:)

btw fyi - i created a jar file from eclipse and unzipped all the files into the folder that contains my .html

March 17, 2005, 10:08 AM
Here is the error dump from that applet...

load: Applet1.class can't be instantiated.


at sun.reflect.InstantiationExceptionConstructorAcces sorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at java.lang.Class.newInstance0(Unknown Source)

at java.lang.Class.newInstance(Unknown Source)

at sun.applet.AppletPanel.createApplet(Unknown Source)

at sun.plugin.AppletViewer.createApplet(Unknown Source)

at sun.applet.AppletPanel.runLoader(Unknown Source)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

March 17, 2005, 10:14 AM
instantiation exception....hmmmm....


March 19, 2005, 10:44 PM
Success! Applet inited!

Problem was in the applet code - wasn't implementing method run in Runnable. Changed the play method to run and declared Applet as non-abstract (i.e. removed the word "Abstract" from class declaration).

Kool - now I can go on and continue developing my applets!

March 19, 2005, 10:57 PM
Great work.