It's not a secret anymore!*
The moose likes Applets and the fly likes Problems while Loading Applet... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Problems while Loading Applet..." Watch "Problems while Loading Applet..." New topic
Author

Problems while Loading Applet...

Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

I am new to Applets, I am using a Applet to load a JPanel to it. This Applet when I try to run through NetBeans I am able to run and see the output. Now when I try this into a html, I am not able to see its output. Can some one help on what should be done here.

My applet code looks like:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

And my html looks like

<html>
<head>
<title></title>
</head>
<body>
<applet code="CubeTestApplet.class" width="300" height="200" codebase="." ></applet>
</body>
</html>

Please help me whats wrong here. Thanks in Advance.


Ananth Chellathurai [Walk on software]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
Are there any messages either in the browser status bar or the Java Console?


Ping & DNS - my free Android networking tools app
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Yes in the status bar I get Loading Java Applet failed is the message.

In the console it is

java.lang.NoClassDefFoundError: CubeApplet (wrong name: com/applet/cube/CubeApplet)

I have the html and the CubeApplet.class in the same directory. I have tried to use a jar which contains this class and specified the jar name in archive attribute, but all my efforts went in vein.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
The directory hierarchy needs to reflect the package structure. The class file must be in a directory called "cubeapplet", which must in a directory called "cube", which must in a directory called "applet", which must be in a directory called "com", and that must be in the same directory as the HTML file.

If you're using a jar file, then that too needs to include the full directory structure.
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Thanks for your helps so far. I am able to execute an sample applet. Now its time for heavy lifting. I am using a JPanel within the applet, the JPanel uses ResourceBundle within it. So when I try to open the panel in the browser I am getting null pointer exeption on loading the resource bundle. Can you help me on this?

java.lang.NullPointerException
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at com.neto2.attest.psd.PSD.<init>(PSD.java:62)

The line number 62 has the code to load a resource bundle.

Thanks in Advance
Ananth
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
Is PSD one of your classes, or is it a 3rd party library? Are there any resource bundles present?
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

PSD is one of my classes which returns a JPanel.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
So is the resource bundle present? Where is it?
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

ResourceBundle resBundle = ResourceBundle.getBundle( Constants.MESSAGES_PROPERTY_FILE, Language.getInstance( ).getLocale( ) );

This was declared in my PSD. My problem was with loading the locale. Then I have loaded the language like this Language.getInstance( ).setLocale( new Locale( "en_US" ) );

Now I am getting a new problem in the console

Java Plug-in 1.5.0_09
Using JRE version 1.5.0_09 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\ananth_chellathurai


----------------------------------------------------
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
p: reload proxy configuration
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>
----------------------------------------------------

sdf -null
java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group
at com.neto2.attest.psd.PSD.getTopCPanel(PSD.java:116)
at com.neto2.attest.psd.PSD.<init>(PSD.java:94)
at com.neto2.attest.psd.PSDApplet.<init>(PSDApplet.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown ...

What could be wrong here?
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

I am posting the constructor of my PSD class here

public PSD( String pktFileName )
{
super( TableLayout.PREFERRED ); // Setting top panel preferred.

super.addStarterPanel( getTopCPanel( resBundle.getString( "CP_Title_Filter" ) ) );
setPsdGPanel( new PSDCanvas( pktFileName ) );

super.add( getBottomCPanel( resBundle.getString( "CP_psd_title" ) ), TableLayout.PREFERRED );

setPsdPacket( new PSDPacketPanel( ) );
CollapsiblePanel psdCPacket = new CollapsiblePanel( " Packet Details" );
psdCPacket.add( getPsdPacket( ) );
super.add( psdCPacket, TableLayout.FILL );

getPsdGPanel( ).addMouseListener( new java.awt.event.MouseAdapter( )
{
public void mouseClicked( java.awt.event.MouseEvent evt )
{
psdGPanelMouseClicked( evt );
}
});
}

This is a working code in swing but I am not able to bring this into the applet. I am in a real hurry to rush this up. Please save me.
[ November 23, 2007: Message edited by: Ananth Chellathurai ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
Are you referencing the jdesktop jar file in the archive attribute of the applet tag?
[ November 23, 2007: Message edited by: Ulf Dittmer ]
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

No I am not using archive attribute in my html.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
Well, then that's your answer. You need to put the jdesktop jar file(s) into the same directory as the HTML file, and then include it in the archive tag.
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Forgive me on my ignorance can you say whats jdesktop jar?
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

I have copied the swing-layout-1.0.jar to my html folder. And added this to the archive attribute but still I get the same exception. java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
I have copied the swing-layout-1.0.jar to my html folder. And added this to the archive attribute but still I get the same exception. java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group


What does your applet tag look like?

Does the swing-layout-1.0.jar file contain the org/jdesktop/layout/GroupLayout$Group class?
John Mclain
Ranch Hand

Joined: Nov 04, 2007
Posts: 30
dear Ananth,

make a thorough look over your applt class,indded it's a member of swing package. to run your applet class from within html page you must run it first in html cnverter and then deploy it in your application.

hope this will help you

cheers
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
Originally posted by John Mclain:
indded it's a member of swing package. to run your applet class from within html page you must run it first in html cnverter and then deploy it in your application.

The jdesktop classes aren't part of Swing, so I'm not sure what you're alluding to. This is a question of classpaths, not a question of using HTML converter.
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Yes the swing-layout-1.0.jar, has the org.jdesktop.layout jar. My applet tag looks like

<APPLET codebase="classes" archive="swing-layout-1.0.jar" code="com/neto2/attest/psd/PSDApplet.class" width=850 height=300></APPLET>

Can you please tell me whats html convertor.

Thanks in Advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
That looks correct, as long as swing-layout-1.0.jar is in the same directory as the HTML file. Let's not confuse the issue by talking about HTML converter; that doesn't help in this case.

The question remains whether swing-layout-1.0.jar actually contains the org/jdesktop/layout/GroupLayout$Group class?
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Ya it has org.layout.GroupLayout class in it.
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Can you help me on what must be done next?

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
I'm just noticing that "jdesktop" probably refers to JDIC - correct? That does include native components which make deployment as an applet somewhat tricky. But here's a lengthy FAQ entry on how to do that; are you following those steps?
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

No I did'nt follow this steps. I will try doing that and get back shortly. But when I am trying a sample with all panel related code within the Applet code I am able to open the applet succesfully. At that time I did'nt follow such steps, I dont know how I was able to get it there and not here. Any how I will try this.

Thanks
Ananth
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

When I unzipped swing-layout-1.0.jar which contains org\jdesktop... inside to my classes directory the applet is able to see the those classes. Now I have some 30 jars in a lib folder parallel to classes, should I have to unwrap all classes to make this Applet work? Can you give me a simple solution?

Ananth
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
No, you should not have to do that. Maybe the JVM has problems accessing the swing-layout-1.0.jar file - does it have its permissions set correctly so that it is publicly accessible? Can you download it by entering its URL in a browser?
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Ulf I have just fixed my problem like this

<APPLET codebase="classes" archive="../lib/swing-layout-1.0.jar" code="com/neto2/attest/psd/PSDApplet.class" width=850 height=350></APPLET>

Thanks for All your helps so far.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems while Loading Applet...
 
Similar Threads
Signed applet getting access denied
viewing applet in IE
applet not working
Can't run my applet on a html page
Sizing Swing object on a JApplet