File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Applet question - .class vs .java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Applet question - .class vs .java" Watch "Applet question - .class vs .java" New topic
Author

Applet question - .class vs .java

James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
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!

Thanks,

-Patrick



Hello. My name is Inigo Montoya. You killed my father. Prepare to die.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
The .class file is created if you compile the .java file without errors.
James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
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?:

init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Owner.Mynotebook\Ch5ItIs\build\classes
compile-single:
run-applet:
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)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
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?


Ping & DNS - my free Android networking tools app
James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
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'
James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
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.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14266
    
  21

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
The tag is called "applet", not "object".
James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
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.
James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
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 ]
James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
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!

-Patrick
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet question - .class vs .java