Jeff Terry

Greenhorn
+ Follow
since Apr 29, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Jeff Terry

I put the images in the base /applet/ directory, and then after changing my code to retrieve the images to

//where thisApplet is a static reference to the "Main" applet class itself:
Main.thisApplet.getImage(Main.thisApplet.getDocumentBase(),imageName))

and now its all working!

Thanks for your help Ulf

13 years ago
Okay, some progress has been made. Following Ulf's suggestions that the structure was wrong, I stopped using the open source Fat Jar to create my jar file, and just used Eclipses regular Export -> Jar File. I wasn't able to get this to also jar up the external mysql-connector jar, so I just copied the mysql jar "com" folder directly into my /applet/ directory.

I was still unable to access the database, until I followed the directions at http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html to self-sign my applet. Hooray! Now the connection to the remote database is successful.

Now the problem I am running into is reading images into the applet from my jar. I am getting the following error:
java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at userInterface.ImageComponent.<init>(ImageComponent.java:34)
at userInterface.Main.init(Main.java:100)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.IllegalArgumentException: input == null!

My ImageComponent code:
I was using this code before deployment for reading in images, but I guess its not very applet friendly?
ClassLoader cL = Thread.currentThread().getContextClassLoader();
InputStream iS = ClassLoader.getSystemResourceAsStream(name);
image = ImageIO.read(iS);

So I changed it to:
URL urlResource = getClass().getResource(name);
System.out.println("Got resource...");
image = Toolkit.getDefaultToolkit().getImage(urlResource);
where name is just a String, i.e. "background-1.gif", "background-2.gif", etc.

The part that seems weird to me is, in my Eclipse project all the images are found in the /images/ directory, however, when I export the project to a jar, they are all dumped directly within the top level of the jar (no images directory). Do you think this could be the cause of the problem? Or am I reading them in incorrectly?
13 years ago
Yes, it was (which it definitely should not have been). I have removed that line and then got the following error:

java.lang.RuntimeException: java.lang.NoClassDefFoundError: userInterface/ImageComponent
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: userInterface/ImageComponent
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(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)
Caused by: java.lang.ClassNotFoundException: userInterface.ImageComponent
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 20 more
Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: userInterface/ImageComponent

So, after taking the ImageComponent class out of the jar and into the /applet/userInterface directory, I then got errors of other classes not being found. I eventually just extracted everything from the jar straight into the /applet/ directory. Errors are now gone, but the applet just crashes on load and doesn't give a chance for any errors (Firefox: black screen applet, IE: frozen Java loader).

Is this the right way to handle applet file structure? If so, whats the point or the "archive" tag and a jar? Doesn't seem like it was ever using it anyway (though I'm sure my assumptions are incorrect).
13 years ago
I think my applet/jar/html's are all in place now, but I can't get past the security errors I am getting when attempting to connect to remote databases.

Reading up on things, I thought the solution may be a crossdomain.xml file placed on the server I was attempting to access. I created one, but now, when I try to run the applet, it just freezes and gives me a black screen (firefox & IE). Chrome still gives errors stating: "Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: Could not initialize class userInterface.Main" (so maybe I shouldn't be so confident in how I set up the applet? Still something wrong? The db connection is occurring during Main's init() though)

*EDIT*: Just found a previous post referring to instructions at "http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html". Checking it out right now.
13 years ago
I have an applet that contains about 30 different class files, all held within two different packages (userInterface and guts), as well as some image files. It also uses an external jar (mysql-connector).

Im having problems viewing it within a browser, though it runs fine in Eclipse. I'm not trying to run it off of a server yet, I'm just putting the project jar file (new.jar) and the html page I create in the same directory (C:/Users/Jeff/Desktop/applet/) on my system, and running it from there.

The class which extends JApplet is in the userInterface package, and is called Main.

Here is my HTML:

<html>
<title>My Applet</title>
<body>
<applet archive='new.jar',
code='userInterface.Main.class',
width=500,
height=500 />
</body>
</html>

I've read through quite a few posts from others experiencing similar issues, but still haven't had any luck after trying to implement their solutions

Thanks for any help you can offer

*EDIT*: I just tried moving 'Main.class' from my jar into a directory (/applet/userInterface/) and changing my html code line to code='userInterface.Main', and am now getting the following errors:

java.lang.RuntimeException: java.lang.ExceptionInInitializerError
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(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)
Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkExit(Unknown Source)
at java.lang.Runtime.exit(Unknown Source)
at java.lang.System.exit(Unknown Source)
at guts.DBHelper.getConnection(DBHelper.java:43)
at userInterface.Main.<clinit>(Main.java:29)
... 21 more
Exception: java.lang.RuntimeException: java.lang.ExceptionInInitializerError

Could this be due to problems connecting to remote db?

I added a java.policy file with:
grant {
permission java.security.AllPermission;
};
to the /applet/ directory, so hopefully this portion of the problem should be fixed.
13 years ago
I'm actually just running it from my desktop at the moment (the html page and the jar file are in the same spot).

The jars structure looks like

newProjectForm_fat.jar
- userInterface package
-class Main is directly in here
- guts package
- .svn directory
- com package
- META-INF package
- org package
<image files>
Hello everyone!

I'm developing a Java applet for the web that I am having trouble deploying using Eclipse.

Info:
It uses an external jar (mysql-connector) in the build path.
The entry class is Main.class (no main method in there, it's just called Main) which is in package userInterfaces
I have tried Export -> JAR File to generate the JAR
I have tried using the open source Fat Jar Exporter to generate the JAR

However, when I try to run the applet within a browser (with the following HTML)
<html>
<title>My Applet</title>
<body>
<applet code="userInterface/Main.class"
archive="newProjectForm_fat.jar"
width=320 height=320>
</applet>
</body>
</html>

It always just shows an error saying that Main.class is not found

java.lang.RuntimeException: java.lang.NoClassDefFoundError: Could not initialize class userInterface.Main
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class userInterface.Main
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(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)

Any help would be appreciated!

(hopefully I put this in the right place, I figured it's probably something wrong I am doing in eclipse)