Solved

Accessing helper classes for an Applet through a jar

Posted on 2007-04-06
7
346 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
  • 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
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!

 

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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
hibernate jars 4 57
ejb example issues 3 47
Eclipse Help Java EE 5,6,7 Documentation, why not Java EE 8 8 39
Fast way to search item into Java Array (Rhino compatible) 2 36
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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:

679 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