• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Applet question - .class vs .java

 
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The .class file is created if you compile the .java file without errors.
 
James Brooks
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
James Brooks
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The tag is called "applet", not "object".
 
James Brooks
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
There's a way to do it better - find it. -Edison. A better tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic