I have a folder with two files inside; the java .class file and the .html file. In my html file I call the .class file as an applet but it sais an error on the website its published to saying it can’t find the .class file. This puzzles me since they are in the same directory and I triple checked for spelling errors.
Here is my .html file…
<html>
<head>
<title>Applet</title>
</head>
<body>
Program<br />
<applet code="testing.class" width="300" height="300"/>
</body>
</html>
and here is my .class file…
import java.awt.Color;
import java.awt.Graphics;
public class testing extends java.applet.Applet{
public void init(){
}
public void paint(Graphics g){
g.drawOval(0,0,250,100);
g.setColor(Color.RED);
g.drawString("My Applet",10,50);
}
}
My .class file is “testing.class” and my html file is “testingpage.html”
Here is the Full Entire error
load: class testing.class not found.
java.lang.ClassNotFoundException: testing.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:690)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3045)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1497)
at java.lang.Thread.run(Thread.java:680)
Exception: java.lang.ClassNotFoundException: testing.class
load: class testing.class not found.
java.lang.ClassNotFoundException: testing.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:690)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3045)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1497)
at java.lang.Thread.run(Thread.java:680)
Exception: java.lang.ClassNotFoundException: testing.class
The
applettag should be:Notice the change in the
codeattribute. Compare to the example code listed in the relevant Java Tutorial:The following is working for me.
http://puu.sh/PebS
TestingApplet.java
testing-applet.html
If this is not working, I have two questions for you…
Did you save the Java as a
.javafile and compile it to produce the correct.classfile?Did you verify your browser is not caching an old incorrect version of the
.htmlfile?Are your
.classand.htmlfiles in the same directory?