Solved

Accessing helper classes for an Applet through a jar

Posted on 2007-04-06
7
349 Views
Last Modified: 2008-02-01
I have an applet that is included in a jar file.  The applet class has an import for a class within package access.  The applet works in Eclipse but when I deploy it and use it with a browser, it loads the applet class and when it tries to access a helper class within the package the error console says it cannot initialize that helper class.  But if its in the jar file and it can find the applet class, why can't it find other classes in the jar?  For instance, I have package.myApplet and package.myHelperClass.  Both classes are in the jar file.  In my applet loader, I have the archive set to the jar, and the code set to package.myApplet.  It loads, but says it cannot initialize package.myHelperClass in the Java Console.

HTML:
<applet archive="myJar.jar" code="package.myApplet" height="200" width="200"></applet>

Contents of myJar.jar:
package/myApplet.class
package/myHelperClass.class

Another note is that I am trying to access the helper class statically, ie myHelperClass.someStaticMethod().  I don't create an instance.
0
Comment
Question by:tmar89
[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
  • 4
  • 3
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 18868032
Please post output of

jar tf myJar.jar
0
 

Author Comment

by:tmar89
ID: 18868422
META-INF/MANIFEST.MF
package/myApplet$1.class
package/myApplet$2.class
package/myApplet$3.class
package/myApplet$4.class
package/myApplet$5.class
package/myApplet$6.class
package/myApplet$7.class
package/myApplet.class
package/myHelperClass.class
0
 

Author Comment

by:tmar89
ID: 18868428
To give more info on the error, Java Console responds with:

Exception in thread "AWT-EventQueue-1" java.lang.NoClassDefFoundError: Could not initialize class package.myHelperClass
      at package.myApplet$1.actionPerformed(myApplet.java:42)
      at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
      at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
      at java.awt.Component.processMouseEvent(Unknown Source)
      at javax.swing.JComponent.processMouseEvent(Unknown Source)
      at java.awt.Component.processEvent(Unknown Source)
      at java.awt.Container.processEvent(Unknown Source)
      at java.awt.Component.dispatchEventImpl(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)

myApplet.java line 42:
myHelperClass.checkEvent();
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:tmar89
ID: 18868443
After rearranging some code, it turns out it is scope related.  I was calling the class from an inline method through the addActionListener method and it was not able to find the myHelperClass class.  I didn't expect this to be an issue because it works fine in the IDE but not as a standalone applet.  Here is the faulty code:

eventButton.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    myHelperClass.checkEvent();
  }});

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 18868804
Yes - you'll find it easier with scope, readability and deployability if you use private inner classes with descriptive names instead of anonymous classes. Another option is to make the applet itself implement ActionListener
0
 

Author Comment

by:tmar89
ID: 18869611
Yeah, that was exactly what I did.  I'll give you the credit for helping me brainstorm through this problem.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18870014
:-)
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

623 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