Solved

Accessing helper classes for an Applet through a jar

Posted on 2007-04-06
7
344 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 97
maven project error 5 55
ForLoop Example 3 48
windows explorer path to command prompt 5 44
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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

770 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