Forums Register Login
Applet question - .class vs .java
Hi again,

Question about applets this time. When using Applet Viewer in NetBeans (right-click the .java app -> run file), I get the error
class Applets/myApplet.class not found. I started this Applet as a normal Java class, so it has a .java extension, and not a .class extension. How do I convert to .class or create a .class file? My book does not help at all!



The .class file is created if you compile the .java file without errors.
Hmmm, well, then, that's not it. When I click 'run file', a blank applet opens, and at the bottom it says 'applet not initialized'. Below are the messages I got, any ideas?:

Compiling 1 source file to C:\Documents and Settings\Owner.Mynotebook\Ch5ItIs\build\classes
load: class ch5itis/myApplet.class not found.
java.lang.ClassNotFoundException: ch5itis.myApplet.class
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:183)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:127)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:626)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:778)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:707)
at sun.applet.AppletPanel.run(AppletPanel.java:361)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.io.FileNotFoundException: C:\Documents and Settings\Owner.Mynotebook\Ch5ItIs\build\classes\ch5itis\myApplet\class.class (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161)
at sun.applet.AppletClassLoader.getBytes(AppletClassLoader.java:295)
at sun.applet.AppletClassLoader.access$100(AppletClassLoader.java:44)
at sun.applet.AppletClassLoader$1.run(AppletClassLoader.java:173)
at java.security.AccessController.doPrivileged(Native Method)
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:170)
... 8 more
BUILD SUCCESSFUL (total time: 7 seconds)
Is the class in package "ch5itis"? That's what the error message says it is expecting. What does the applet tag in the HTML file look like?
Yeah, I declared package Ch5ItIs;, but that doesn't help. I'm just using NetBeans; right-click the class name, then click 'run file'. I shouldn't have to use an HTML file this way, right? Again, the applet window opens, but no text appears on the applet, and at the bottom is says
'Start: applet not initialized'
I even created the below HTML doc and viewed it in IE7, but it just had the outline 720x560 size with no content, had the x in the upper left.

Originally posted by Patrick Brooks:
Yeah, I declared package Ch5ItIs;, but that doesn't help. ...

Java is case-sensitive, so "Ch5ItIs" with a capitals C and I is not the same as "ch5itis" with lower-case letters.
The tag is called "applet", not "object".
I actually did declare it ch5ItIs, that was just a typing slip-up here on the BB. Ulf: my book says it is better to use <object> than <applet>, but that they do the same thing.
my book says it is better to use <object> than <applet>, but that they do the same thing.

There are reasons why it would be preferable in some situations, but not generally. And it doesn't literally do the same thing in the sense that "applet" can be replaced by "object", and everything else works the same. The object tag is much more complicated. Try an applet tag and see what happens.
Thanks for the explanation, Ulf. I tried the <applet> tag, and the same thing happened. Any ideas? I know it's hard to troubleshoot without the NetBeans project laid out in front of you.
What does you applet tag look like, and where are the various applet files, i.e. what is the directory layout? For the tag to work in the way you posted earlier, the class files need to be in the same directory as the HTML file.

Are there any messages in the Java Console?
[ April 14, 2007: Message edited by: Ulf Dittmer ]
Why, silly me, I had declared a wrong package name, or, rather, camel-cased it when I shouldn't have. Thanks for the help, Ulf!

Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

All times above are in ranch (not your local) time.
The current ranch time is
Nov 22, 2017 00:47:13.