Solved

Accessing helper classes for an Applet through a jar

Posted on 2007-04-06
7
342 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now