1

I am working in an applet, when I use Eclipse to run it I don't have any problem but when I try to load the applet on my Internet Explorer browser, it gives me this error:

java.lang.reflect.InvocationTargetException

I don't know what to do and why is not working with my browser and yes with Eclipse.

Any idea?

I run it using appletviewer and the problem came when I pressed the Exit button, which I have to exit the game. It doesn't exit the game actually... now I am even more lost..

------------- stack trace

C:\Course Technology\src>appletviewer TestJAlienHunt.html
Exception in thread "AWT-EventQueue-1" java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "exitVM.0")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:366)
    at java.security.AccessController.checkPermission(AccessController.java:555)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkExit(SecurityManager.java:761)
    at java.lang.Runtime.exit(Runtime.java:105)
    at java.lang.System.exit(System.java:960)
    at JAlienHunt.actionPerformed(JAlienHunt.java:97)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6505)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6270)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4861)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4687)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)

    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Component.dispatchEvent(Component.java:4687)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703)
    at java.awt.EventQueue.access$000(EventQueue.java:102)
    at java.awt.EventQueue$3.run(EventQueue.java:662)
    at java.awt.EventQueue$3.run(EventQueue.java:660)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:676)
    at java.awt.EventQueue$4.run(EventQueue.java:674)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre ad.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)

    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)

    at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
Roman C
  • 49,761
  • 33
  • 66
  • 176
dalex
  • 37
  • 6
  • did you try other browser? like google chrome? – Russel Yang Apr 16 '13 at 23:16
  • does your applet try to access any system resources? Maybe read/write some files? – 0x6C38 Apr 16 '13 at 23:18
  • 1
    Could you post the full exception and the code where is the exception thrown(if possible)? – NeplatnyUdaj Apr 16 '13 at 23:18
  • Russel, when I try to open it in Google chrome nothing happens, just an empty page, but the same happens with another applet I had created that works perfect. Maybe I don't know how to open it properly... – dalex Apr 16 '13 at 23:38
  • Mr D., no.. at least not intentional. I am not working with files so far. – dalex Apr 16 '13 at 23:39
  • user2266098, that is a big question, I am not checking exceptions in my code, I don't know where the exception is generated. I was browsing how can I deal with this before asking here, but not a clue. – dalex Apr 16 '13 at 23:41
  • I don't have to much experience with Eclipse, is there any way to find out where the exception is generated? When I run the applet I don't get any exception. – dalex Apr 16 '13 at 23:43
  • 1
    `InvocationTargetException` is usually `caused by` other things, open the [Java Console](http://www.java.com/en/download/help/javaconsole.xml) & copy/paste the *entire stack trace* as an [edit to the question](http://stackoverflow.com/posts/16048785/edit). – Andrew Thompson Apr 17 '13 at 03:03

1 Answers1

2

An applet is not allowed to call System.exit. Other applets made by other people may be using that JVM, after all.

In general, an applet "ends" when the user chooses to close or leave the page (which causes the applet's stop method to be called). The applet cannot decide on its own when its operation ends.

In theory, you could make your applet display a blank rectangle or something, but really, an "Exit" function simply doesn't make sense in an applet, and shouldn't be present to begin with.

VGR
  • 40,506
  • 4
  • 48
  • 63