Results 1 to 5 of 5
  1. #1
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default [SOLVED] [newbie] running an applet ??

    I'm trying to get an applet up and running, however, the applet is not being displayed.

    I copied the .java file to an .html file and tried to tinker with the commands.

    :confused:

    1. The code
    Java Code:
    package homenetwork.bkr.training;
    
    import java.awt.*;
    import javax.swing.*;
    
    [B]/*
     * <applet code="NotHelloWorldApplet.class" width="300" height="300">
     * </applet>
     */[/B]
    @SuppressWarnings("serial")
    public class NotHelloWorldApplet extends JApplet {
    	
    	public void init()
    	{
    		EventQueue.invokeLater(new Runnable()
    		{
    			public void run()
    			{
    				JLabel label = new JLabel("Not a Hello World Applet", SwingConstants.CENTER);
    				add(label);
    			}
    		});
    	}
    
    }
    2. Command line
    Java Code:
    >copy NotHelloWorldApplet.java NotHelloWorldApplet.html
            1 file(s) copied.
    
    >
    ....
    >appletviewer NotHelloWorldApplet.html
    Warning: <applet> tag requires width attribute.
    
    >appletviewer NotHelloWorldApplet.html 300
    Warning: <applet> tag requires width attribute.
    I/O exception while reading: C:\Users\Administrator\workspace\NotHelloWorldApple
    t\src\homenetwork\bkr\training\300 (The system cannot find the file specified)
    
    >appletviewer 300 NotHelloWorldApplet.html
    I/O exception while reading: C:\Users\Administrator\workspace\NotHelloWorldApple
    t\src\homenetwork\bkr\training\300 (The system cannot find the file specified)
    
    >appletviewer
    Usage: appletviewer <options> url(s)
    
    where <options> include:
      -debug                  Start the applet viewer in the Java debugger
      -encoding <encoding>    Specify character encoding used by HTML files
      -J<runtime flag>        Pass argument to the java interpreter
    
    The -J option is non-standard and subject to change without notice.
    
    >appletviewer -debug NotHelloWorldApplet.html
    Initializing jdb ...
    help
    
    VM Started: Warning: <applet> tag requires width attribute.
    
    The application exited
    
    >appletviewer -debug NotHelloWorldApplet.html
    3. Error
    When trying to run it in a browser I get the following error:
    Java Plug-in 1.6.0_13
    Using JRE version 1.6.0_13 Java HotSpot(TM) Kernel VM
    User home directory = C:\Users\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 NotHelloWorldApplet.class not found.
    java.lang.ClassNotFoundException: NotHelloWorldApplet.class
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.FileNotFoundException: C:\Users\Administrator\workspace\NotHelloWorldAppl et\src\homenetwork\bkr\training\NotHelloWorldApple t\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.http://www.protocol.file.FileURLConn...onnect(Unknown Source)
    at sun.net.http://www.protocol.file.FileURLConn...Stream(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unk nown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(U nknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknow n Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 7 more
    Exception: java.lang.ClassNotFoundException: NotHelloWorldApplet.class


    I noted that Google Chrome doesn't seem to install the Java plug-in straightaway. Here's what the program looked like:
    in Google Chrome and
    in Mozilla FF
    Last edited by jon80; 05-31-2009 at 10:14 PM. Reason: updated - syntax error

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    On the command line, at the prompt
    appletviewer NotHelloWorldApplet.html
    should be
    appletviewer NotHelloWorldApplet.java

  3. #3
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    1. Thanks. Does this error mean anything?

    >appletviewer NotHelloWorldApplet.java
    load: class NotHelloWorldApplet.class not found.
    java.lang.ClassNotFoundException: NotHelloWorldApplet.class
    at sun.applet.AppletClassLoader.findClass(AppletClass Loader.java:210)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.applet.AppletClassLoader.loadClass(AppletClass Loader.java:143)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
    at sun.applet.AppletClassLoader.loadCode(AppletClassL oader.java:690)
    at sun.applet.AppletPanel.createApplet(AppletPanel.ja va:785)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java: 714)
    at sun.applet.AppletPanel.run(AppletPanel.java:368)
    at java.lang.Thread.run(Thread.java:619)

    2. Also, any idea why I am getting the errors 'No class found' when I try to place an .html file in the same directory as a .class file:

    NotHelloWorldApplet.html
    Java Code:
    <html>
    <head><title>Not a hello world application</title></head>
    
    <body>
    <applet code="NotHelloWorldApplet.class" width="300" height="300">
    </applet>
    </body>
    </html>
    Last edited by jon80; 05-31-2009 at 10:31 PM.

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Does this error mean anything?
    >appletviewer NotHelloWorldApplet.java
    load: class NotHelloWorldApplet.class not found.

    Java cannot find your compiled class file. It should be plainly visible in the current directory. The file name and the name of the public outer class in it must be exactly the same.

    Also, any idea why I am getting the errors 'No class found' when I try to place an .html file in the same directory as a .class file:
    Avoid using an html file for developing applets. Browsers and the java plug–in, aka, JRE, cache the class files and will not use/recognize newer/recompiled files. Use the appletviewer instead.

  5. #5
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

Similar Threads

  1. First Applet not running on browsers
    By Centinela66 in forum Java Applets
    Replies: 11
    Last Post: 10-09-2008, 02:58 PM
  2. super newbie, running from terminal
    By pbpersson in forum New To Java
    Replies: 16
    Last Post: 08-11-2008, 06:42 AM
  3. Getting url of page applet is running on
    By damounh in forum Java Applets
    Replies: 1
    Last Post: 05-09-2008, 06:49 PM
  4. Newbie in applet, Help me
    By barney in forum Java Applets
    Replies: 1
    Last Post: 08-07-2007, 08:14 AM
  5. Sounds don't play when running applet
    By leonard in forum Java Applets
    Replies: 1
    Last Post: 08-06-2007, 09:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •