Solved

Cannot see applet in browser

Posted on 2004-10-24
502 Views
Last Modified: 2013-11-23
Hi,

I have j2sdk1.4.2 in my computer and works fine compiling and running java program. But I can see the applet in browser. What I could see was only a grey rectangle. What is wrong and how could i rectify.

Thanks
0
Question by:ricjava
    44 Comments
     
    LVL 92

    Expert Comment

    by:objects
    check the java console for errors.
    0
     
    LVL 10

    Expert Comment

    by:NetworkArchitek
    Hi ricjava,
    Did you update your JRE as well? Also, check to make sure you do not have any misspellings in your code. Your class name must match up correctly.


    Cheers!
    0
     

    Author Comment

    by:ricjava
    hi NetworkArchiteck - no misspellings :)

    hi objects - how do i check the java console?
    0
     
    LVL 92

    Accepted Solution

    by:
    open it via the java icon in your system tray.
    if its not there, your browser may not be using the plugin as your default vm (which could be the cause of your problems). You can set the default VM thru IE's advanced options, or via the plugin control panel.
    0
     

    Author Comment

    by:ricjava
    I have checked the option Java Console Enable in IE and restarted but still cannot see my applet working in browser - only grey rectangle.

    Also how do I set system tray to have java icon?
    0
     
    LVL 92

    Expert Comment

    by:objects
    if its not there, it probably means that the plugin isn't running.
    check that the plugin is set as the default vm for your browser.
    0
     

    Author Comment

    by:ricjava
    do i have to install JRE as well?

    Ok, now I go to IE view, Java Console.

    I saw the error of

    Error loading class: HelloWorld
    java.lang.NoClassDefFoundError
    java.lang.ClassNotFoundException: HelloWorld
          at com/ms/vm/loader/URLClassLoader.loadClass
          at com/ms/vm/loader/URLClassLoader.loadClass
          at com/ms/applet/AppletPanel.securedClassLoad
          at com/ms/applet/AppletPanel.processSentEvent
          at com/ms/applet/AppletPanel.processSentEvent
          at com/ms/applet/AppletPanel.run
          at java/lang/Thread.run

    0
     
    LVL 92

    Expert Comment

    by:objects
    does your applet use java2 features?
    If so then you'll need to use the plugin to run it instead of the MS VM.
    0
     

    Author Comment

    by:ricjava
    It is just a simple two files

    <HTML>
    <HEAD>
    <TITLE> A Simple Program </TITLE>
    </HEAD>
    <BODY>

    Here is the output of my program:
    <APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>
    </APPLET>
    </BODY>
    </HTML>

    that is my html file and  the HelloWorld.class is in the same folder
    0
     

    Author Comment

    by:ricjava
    This is my applet code

    import java.applet.Applet;
    import java.awt.Graphics;

    public class HelloWorld extends Applet {
        public void paint(Graphics g) {
            g.drawString("Hello world!", 50, 25);
        }
    }


    0
     
    LVL 9

    Expert Comment

    by:Ovi
    Seems to me that your applet class is not correctly seen by the browser. Please checck the <applet> tag for path consistency to your classpath.

    For example, if your HelloWorld class file is located in the same directory as the html page which is suposed to launch the applet, the tag should look like:

    <applet codebase="." class="HelloWorld.class" code="HelloWorld" width="100" height="100">
    ... applet parameters if any .....
    </applet>

    If your class file is located in a directory called for example 'classes', located on the same level as the html page, the tag must be updated accordingly, like this:

    <applet codebase="./classes/" class="HelloWorld.class" code="HelloWorld" width="100" height="100">
    ... applet parameters if any .....
    </applet>


    This should solve your problem.
    0
     

    Author Comment

    by:ricjava
    I have installed j2sdk1.4.2 in my computer months ago and running fine with java application.

    Doesn't installing j2sdk1.4.2  make the plug-in available?
    0
     
    LVL 9

    Expert Comment

    by:Ovi
    Seems to me that your applet class is not correctly seen by the browser. Please checck the <applet> tag for path consistency to your classpath.

    For example, if your HelloWorld class file is located in the same directory as the html page which is suposed to launch the applet, the tag should look like:

    <applet codebase="." class="HelloWorld.class" code="HelloWorld" width="100" height="100">
    ... applet parameters if any .....
    </applet>

    If your class file is located in a directory called for example 'classes', located on the same level as the html page, the tag must be updated accordingly, like this:

    <applet codebase="./classes/" class="HelloWorld.class" code="HelloWorld" width="100" height="100">
    ... applet parameters if any .....
    </applet>


    This should solve your problem.
    0
     

    Author Comment

    by:ricjava
    Ovi - i tried your recommendation but didn't work
    0
     
    LVL 9

    Expert Comment

    by:Ovi
    Tell me how are the files stored on your computer?
    0
     
    LVL 9

    Expert Comment

    by:Ovi
    ... is by any chance your class stored in a .jar file? If yes, the applet tag must look like this:
    <applet codebase="." archive="your_jar_file.jar" class="HelloWorld.class" code="HelloWorld" width="100" height="100">
    ... applet parameters if any .....
    </applet>
    0
     
    LVL 9

    Expert Comment

    by:Ovi
    Error loading class: HelloWorld
    java.lang.NoClassDefFoundError
    java.lang.ClassNotFoundException: HelloWorld

    The only reason you get this exception is because the virtual machine cannot find your class, to load'it and launch. There is no other cause than incorrect classpath setup.
    0
     

    Author Comment

    by:ricjava
    i have two files: helloworld.html and HelloWorld.class, both in c:\myprogram folder.

    Content of helloworld.html

    <HTML>
    <HEAD>
    <TITLE> A Simple Program </TITLE>
    </HEAD>
    <BODY>

    Here is the output of my program:
    <APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>
    </APPLET>
    </BODY>
    </HTML>

    content of HelloWorld.java

    import java.applet.Applet;
    import java.awt.Graphics;

    public class HelloWorld extends Applet {
        public void paint(Graphics g) {
            g.drawString("Hello world!", 50, 25);
        }
    }


    Problem: When I open the browser with url of C:\myprogram\helloworld.html
    I got grey rectangle.

    Also on this page http://java.sun.com/docs/books/tutorial/uiswing/components/applet.html
    I also saw a grey rectangle

    0
     
    LVL 92

    Expert Comment

    by:objects
    compile your applet with "-target 1.1"

    eg.

    javac -target 1.1 HelloWorld.java
    0
     

    Author Comment

    by:ricjava
    i got a warning

    Warning: classic VM not supported;client VM will be used
    0
     
    LVL 92

    Expert Comment

    by:objects
    > There is no other cause than incorrect classpath setup.

    not true, it can be caused by many things.
    in fact the classpath should have little affect on an applet.
    0
     
    LVL 9

    Expert Comment

    by:Ovi
    Please update the applet tag with all valid parameters, setup as previously described in my message.
    0
     
    LVL 9

    Expert Comment

    by:Ovi
    >>not true, it can be caused by many things.

    Like what? Please be so kind and share your knowledge with me on this too :). Thank you.
    0
     
    LVL 92

    Expert Comment

    by:objects
    > i got a warning
    > Warning: classic VM not supported;client VM will be used

    running what command exactly?
    0
     

    Author Comment

    by:ricjava
    hi objects - I can see the applet working now after i compiled with
    javac -target 1.1 HelloWorld.java

    By the way, does it mean that my browser is using 1.1 vm?
    0
     
    LVL 92

    Expert Comment

    by:objects
    > does it mean that my browser is using 1.1 vm?

    that is correct, the MS VM only supports 1.1.
    0
     

    Author Comment

    by:ricjava
    I don't want to use Ms VM, what should I do?

    I already have jsdk1.4.2 installed in my computer
    0
     
    LVL 92

    Expert Comment

    by:objects
    you need to set IE to use the plugin as the default VM.
    This can be done from the advanced options, or the plugin control panel.
    0
     
    LVL 92

    Expert Comment

    by:objects
    thats assuming that the plugin is installed :)
    (it should be by default)
    0
     

    Author Comment

    by:ricjava
    i can see java plugin under the Add or Remove program

    I can see Java 2 SDK, SE v1.4.2 only.

    I plan to remove it and download the sdk from sun website again to install.
    0
     

    Author Comment

    by:ricjava
    can't see java plugin under the Add or Remove program
    0
     

    Author Comment

    by:ricjava
    or is it necessary to do that?
    0
     
    LVL 92

    Expert Comment

    by:objects
    you should have "Java2 Runtime Environment"
    If you don't then you'll need to install it.
    0
     
    LVL 9

    Expert Comment

    by:Ovi
    The plugin is not visible. Instead you see the JDK and the JRE. They are installed automatically. The plugin also is installed automatically into your system, as part of the JRE.

    You just need to go in Internet Explorer->Tools->InternetOptions->Advanced tab->Select the "Use JRE 1.4 for <applet> (requires restart)".
    0
     
    LVL 9

    Expert Comment

    by:Ovi
    The plugin should be visible under Control Panel -> Java entry. That is the Java Plug-in Control Center, from which you should be able to enable the plug-in for your browser.
    0
     

    Author Comment

    by:ricjava
    You mean I should see the Java entry in Start ->Settings->Control Panel?
    0
     
    LVL 9

    Expert Comment

    by:Ovi
    yes, there should e an entry called Java. That's one way of setting the plugin. I recomend you to do'it from  your browser too.
    0
     
    LVL 92

    Expert Comment

    by:objects
    > The plugin should be visible under Control Panel -> Java entry

    mention that earlier.
    But if you don't have Java Runtime Environment" in your Add/Remove programs then you won't have the control panel.
    0
     

    Author Comment

    by:ricjava
    yes, I dont' have the Java Runtime Environment in my Add/Remove program..and therefore no Java entry in Control Panel....


    So i need to  download the jre to install it. The jre version doesn't have to be the same version as my j2sdk1.4.2, isn't it?
    0
     
    LVL 92

    Expert Comment

    by:objects
    no it doesn't.
    1.4.1_06 is the latest I think
    0
     
    LVL 92

    Expert Comment

    by:objects
    i mean 1.4.2_06
    :)
    0
     
    LVL 9

    Expert Comment

    by:Ovi
    Normaly when you have installed the J2SDK, the JRE get's automatically installed too. In any case, go to Sun site and download the JRE. I suggest to use the same version for compatbility issues, even if I did not find any problem like this in my previous experience (you can have multiple JVM installations on the same computer).
    0
     
    LVL 9

    Expert Comment

    by:Ovi
    1.5.0 is the latest, from Tiger release.
    0
     

    Author Comment

    by:ricjava
    i can now see the applets working already after i installed jre. Initially, I thought I have plug-in as I already installed j2sdk1.4.2.  Actually, I didn't have it.

    Thanks for everyone's help.

    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    why to use string 10 47
    fizzArray2 challenge 1 29
    linearIn  challenge 23 38
    How Complex Is This Java Course ? 9 32
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now