here i've created the first applet but it is not working,

import java.applet.Applet; 
 import java.awt.*; 
 
 public class FirstApplet extends Applet {
 
     public void paint(Graphics g) {
       g.drawString("Look at me, I'm a Java Applet!",10,50); 
    }
 }

i am getting no errors but when i am opening the html file it is giving error,

here is the html code,

<applet code="FirstApplet.class" width="300" height ="300">

Erorr:

Java Plug-in 1.6.0_20
Using JRE version 1.6.0_20-b02 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Administrator
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------


load: class FirstApplet.class not found.
java.lang.ClassNotFoundException: FirstApplet.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.6.0_20\bin\FirstApplet\class.class (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 7 more
Exception: java.lang.ClassNotFoundException: FirstApplet.class
load: class FirstApplet.class not found.
java.lang.ClassNotFoundException: FirstApplet.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.6.0_20\bin\FirstApplet\class.class (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 7 more
Exception: java.lang.ClassNotFoundException: FirstApplet.class
load: class FirstApplet.class not found.
java.lang.ClassNotFoundException: FirstApplet.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.6.0_20\bin\FirstApplet\class.class (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 7 more
Exception: java.lang.ClassNotFoundException: FirstApplet.class
Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException: component argument pData
at sun.java2d.windows.GDIBlitLoops.nativeBlit(Native Method)
at sun.java2d.windows.GDIBlitLoops.Blit(Unknown Source)
at sun.java2d.pipe.DrawImage.blitSurfaceData(Unknown Source)
at sun.java2d.pipe.DrawImage.renderImageCopy(Unknown Source)
at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
at sun.java2d.pipe.ValidatePipe.copyImage(Unknown Source)
at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Edited 6 Years Ago by Xufyan: n/a

Caused by: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.6.0_20\bin\FirstApplet\class.class (The system cannot find the path specified)

It looks like the browser or appletviewer is looking for the applet in the wrong place. You should have the .html file and the .class file in the same directory so the browser or appletviewer can find your class.

OK. I just looked a little more closely at the error message. It's looking for class.class in a directory called FirstApplet. The piece of HTML you show above looks good. Can you paste the whole HTML file?

I was able to run your applet in the browser using the code you pasted above.

here is the html code,

<HTML>
 <HEAD>
 <TITLE>My First Java Applet</TITLE>
 </HEAD>
 <BODY>
 Here's my first Java Applet: <BR><BR>
 
 <applet code="FirstApplet.class" width="300" height ="300">
 
 </BODY>
 </HTML>

and both of the files are in C:\Program Files\Java\jdk1.6.0_20\bin , there is no FirstApplet directory ..

OK. I'm not sure what the problem is. I am able to run your code. It might be a re-load in the browser problem. Try typing x in the Java Console, which will clear the classloader cache and then reload your applet. See if that works.

Yes it is clearly a local problem. But not uncommon, judging from all the forum posts and bug reports on this subject. I haven't seen any useful solution. Most people seem to thing it has to do with the applet/object/embed tag in html. But the same ClassotFoundException is reported no matter what applet you try to load from the Internet. Even dema applets at sun, oracle or w3schools generate the same type of error.
I've tested to write the url to the class- ot jar-file named in he tag. And the file is downloaded as expected. I can even open the jar-files and see what classes and other resources theu contain. I've also tried downloading some of my own applets the same way to see if something has been altered. But I get exectly the file I should.
I've removed and reinstalled the JRE over and over (32 bit, 64 bit and both, JRE 6 & 7) with exactly the same result.
After I reinstalled eclipse (a standalone program written in java) it says I have no JVM installed when I try to run the program. It looks for a file "javaw.exe" in a directory under eclipse but can't find it. However, the file exists where it should and seems to be intact. Something must be blocking my JVM or it in turn misses one or more crusial files.
I contacted Oracle some 10 days ago with logs, system info and all and I was told someone should get back to me within 48 hours. However, I've got no reply from them.
Now I'm running out of good ideas.

This article has been dead for over six months. Start a new discussion instead.