Meaningless Drivel is fun!*
The moose likes Applets and the fly likes Problem running Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Problem running Applet" Watch "Problem running Applet" New topic
Author

Problem running Applet

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 818
Applets runs fine from commandline using appletviewer but from the browser it doesn't. Gives the following details. Any suggestions on whats wrong? Thanks.


Java Plug-in 1.6.0_17
Using JRE version 1.6.0_17-b04 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Administrator
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
java.lang.reflect.InvocationTargetException
at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown Source)
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.RuntimeException: java.lang.IllegalAccessException: Class sun.plugin2.applet.Plugin2Manager$12 can not access a member of class mcsDraw with modifiers ""
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(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.IllegalAccessException: Class sun.plugin2.applet.Plugin2Manager$12 can not access a member of class mcsDraw with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
... 9 more
Exception: java.lang.reflect.InvocationTargetException
java.lang.NullPointerException
at sun.plugin2.applet.Plugin2Manager.findAppletJDKLevel(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NullPointerException
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Your applet must be a public class.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 818
My applet is a public class. If I run using appletviewer all is well. When I have it embedded on a html page it stays the same, although changes have been made and the code has been regenerated. Any idea why and what I can do to resolve this problem? Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

The error message appears to disagree with you. It appears to say your applet is declared with default access and not with public access. But perhaps it's the zero-argument constructor which is declared that way.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
But perhaps it's the zero-argument constructor which is declared that way.

And just to make sure we're all on the same page - an applet should never have an explicit constructor. That's bound to cause unwanted effects.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 818
It doesn't have a constructor. Just an init, paint, and one other private function.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Then you're going to have to declare the applet class public.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 818
It already is :
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2180
    
    7
One line doesn't help us see what you are doing.

Post a SSCCE that demonstrates the problem.

These days people usually write Swing applets not AWT applets. You can start with the Swing tutorial on How to Make Applets
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 818
Hi, Thanks for the info guys. Rob, when using the JApplet what can I use to determine the size of the JApplet? Right now I use Applet's getSize method to retrieve and assign to a Dimension object. What should I use for determing height and width here? Thanks.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 818
NM. I see what I did wrong - Had the wrong import for JApplet.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Rob Hunter wrote:It already is :

The error message was referring to a class named "mcsDraw".
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 818
I had renamed it afterwards.
Andrew Thompson
Ranch Hand

Joined: Aug 05, 2010
Posts: 77
    
    5
Rob Hunter wrote:I had renamed it afterwards.


Reading that comment I am not clear. Does that mean you have now solved this problem?

If not, I expect the solution will lie in that SSCCE - linked earlier.


Andrew Thompson
http://pscode.org/
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 818
The problem seems to be resolved, not by renaming the class though. I had another browser window open that I wasn't aware of and that may have been causing the persistent of the old style of the applet. Everything seems to be fine now if I close down all instances and re-open.
Andrew Thompson
Ranch Hand

Joined: Aug 05, 2010
Posts: 77
    
    5
Rob Hunter wrote:..causing the persistent of the old style of the applet. ..


'Class caching'. It is a common problem with applet testing in browsers.

To clear the cache, ensure the Java Console is visible (it is configurable within the Java Control Panel), and type 'x' while it has focus. Then refresh the web page.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem running Applet