1

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
4
  • @MarkByers it's more than likely a slip while typing as he refers to it as an .html file beforehand. Commented Aug 6, 2012 at 20:42
  • Yea I just edited my post. it looked weird cuz I was messing around with it before I asked and forgot to change it back Commented Aug 6, 2012 at 20:52
  • yea sorry about the mixup I just fixed it ;) Commented Aug 6, 2012 at 20:53
  • The code attribute should not have .class appended. The applet element was never intended to be self-closed. Can you put the HTML and class file at an URL somewhere so that we can see it fail? Commented Aug 8, 2012 at 0:26

2 Answers 2

4

The applet tag should be:

<applet code=testing.class width="300" height="300" />

Notice the change in the code attribute. Compare to the example code listed in the relevant Java Tutorial:

<applet code=Applet1.class width="200" height="200">
Your browser does not support the <code>applet</code> tag.
</applet> 

The following is working for me.

http://puu.sh/PebS

TestingApplet.java

import java.applet.Applet;

import java.awt.Color;
import java.awt.Graphics;

public final class TestingApplet extends Applet {

  public void paint(final Graphics g){
    g.drawOval(0, 0, 250, 100);
    g.setColor(Color.RED);
    g.drawString("My Applet", 10, 50);
  }
}

testing-applet.html

<html>
  <head>
    <title>Applet</title>
  </head>
  <body>
    Program <br />
    <applet code=TestingApplet.class width="300" height="300" />
  </body>
</html>

If this is not working, I have two questions for you...

  • Did you save the Java as a .java file and compile it to produce the correct .class file?

  • Did you verify your browser is not caching an old incorrect version of the .html file?

  • Are your .class and .html files in the same directory?

Sign up to request clarification or add additional context in comments.

7 Comments

@user1500134 try without the quotes around the code attribute value.
It is working fine for me; see this screenshot. The Java code is here and the HTML here. Make sure your browser is not caching the old HTML file.
Did you save the Java as a .java file and compile it to produce the correct .class file? Did you verify your browser is not caching an old incorrect version of the HTML file?
Hmmm, I closed my browser and reloaded the page but still isn't working... My current code looks identical to yours (except the file name(s)) so idk... i'll keep investigating
I compiled the .java and went to my eclipse workspace and took the .class version from the "bin" folder
|
0

I am pretty sure that you're not openning the correct HTML file. Use your File Browser (Finder I guess ;) ) and look for the file in the Netbeans project directory. It should be in /build/classes/.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.