[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Cannot see applet in browser

Posted on 2004-10-24
44
Medium Priority
?
528 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
Comment
Question by:ricjava
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 17
  • 14
  • 12
  • +1
44 Comments
 
LVL 92

Expert Comment

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

Expert Comment

by:NetworkArchitek
ID: 12397396
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
ID: 12397422
hi NetworkArchiteck - no misspellings :)

hi objects - how do i check the java console?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 12397436
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
ID: 12397494
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
ID: 12397546
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
ID: 12397572
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
ID: 12397578
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
ID: 12397581
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
ID: 12397586
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
ID: 12397600
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
ID: 12397601
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
ID: 12397607
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
ID: 12397616
Ovi - i tried your recommendation but didn't work
0
 
LVL 9

Expert Comment

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

Expert Comment

by:Ovi
ID: 12397645
... 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
ID: 12397656
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
ID: 12397661
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
ID: 12397665
compile your applet with "-target 1.1"

eg.

javac -target 1.1 HelloWorld.java
0
 

Author Comment

by:ricjava
ID: 12397678
i got a warning

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

Expert Comment

by:objects
ID: 12397684
> 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
ID: 12397692
Please update the applet tag with all valid parameters, setup as previously described in my message.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 12397701
>>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
ID: 12397711
> i got a warning
> Warning: classic VM not supported;client VM will be used

running what command exactly?
0
 

Author Comment

by:ricjava
ID: 12397723
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
ID: 12397725
> 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
ID: 12397731
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
ID: 12397747
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
ID: 12397749
thats assuming that the plugin is installed :)
(it should be by default)
0
 

Author Comment

by:ricjava
ID: 12397808
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
ID: 12397815
can't see java plugin under the Add or Remove program
0
 

Author Comment

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

Expert Comment

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

Expert Comment

by:Ovi
ID: 12397876
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
ID: 12397888
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
ID: 12397943
You mean I should see the Java entry in Start ->Settings->Control Panel?
0
 
LVL 9

Expert Comment

by:Ovi
ID: 12397958
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
ID: 12397964
> 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
ID: 12397988
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
ID: 12398001
no it doesn't.
1.4.1_06 is the latest I think
0
 
LVL 92

Expert Comment

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

Expert Comment

by:Ovi
ID: 12398014
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
ID: 12398018
1.5.0 is the latest, from Tiger release.
0
 

Author Comment

by:ricjava
ID: 12398300
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

650 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