小程序中的 java.lang.reflect.invocacytargetexception 错误 [已关闭]

2024-03-17

我的应用程序作为应用程序运行时没有错误,但作为小程序会抛出以下错误:

java.lang.reflect.invokingtargetException

这是我第一次尝试将我的应用程序用作小程序,所以我可能做错了什么,但这是我的主类:

 package main;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JApplet;
import javax.swing.JFrame;

public class MainGame extends JApplet {
    private static final long serialVersionUID = 1L;
    public static final String NAME = "Physics - Projectile Motion Example";
    public static final int HEIGHT = 160;
    public static final int WIDTH = HEIGHT * 16 / 9;
    public static final int SCALE = 4;

    private long reportedFramerate;
    long framerate = 1000 / 60;
    // time the frame began
    long frameStart;
    // number of frames counted this second
    long frameCount = 0;
    // time elapsed during one frame
    long elapsedTime;
    // accumulates elapsed time over multiple frames
    long totalElapsedTime = 0;
    // the actual calculated framerate reported


    public MainGame() {
        run();
    }

    public void run() {
        JFrame frame = new JFrame(MainGame.NAME);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new BorderLayout());


        OptionsPanel options = new OptionsPanel();
        GamePanel game = new GamePanel(options);

        frame.setSize(new Dimension ( WIDTH * SCALE, HEIGHT * SCALE ));

        frame.add(game, BorderLayout.CENTER);
        frame.add(options, BorderLayout.SOUTH);
        frame.setLocationRelativeTo(null);
        frame.setResizable(false);
        frame.setVisible(true);
        while(true) {
            frameStart = System.currentTimeMillis();

            if(options.isStartGame() == true) {
                game.run();
            }
            else {
                game.reset();
            }

            // calculate the time it took to render the frame
            elapsedTime = System.currentTimeMillis() - frameStart;
            // sync the framerate
            try {
                // make sure framerate milliseconds have passed this frame
                if (elapsedTime < framerate) {
                    Thread.sleep(framerate - elapsedTime);
                } else {
                    // don't starve the garbage collector
                    Thread.sleep(5);
                }
            } catch (InterruptedException e) {
                break;
            }
            ++frameCount;
            totalElapsedTime += (System.currentTimeMillis() - frameStart);
            if (totalElapsedTime > 1000) {
                reportedFramerate = (long) ((double) frameCount
                        / (double) totalElapsedTime * 1000.0);
                // show the framerate in the applet status window
                //System.out.println("fps: " + reportedFramerate);
                // repaint();
                frameCount = 0;
                totalElapsedTime = 0;

                //System.out.println(reportedFramerate);
            }
        }
    }

    public void init() {
        new MainGame();
    }
    public void start() {
        System.out.println("started");
    }
    public void stop() {
        System.out.println("Stopped");
    }
    public void destroy() {

    }


    public static void main(String[] args) {
        new MainGame();
    }

}

对象的 HTML:

<p>
<object type="application/x-java-applet"
    name="physics" width="360" height="320">
    <param name="code" value="main.MainGame.class" />
    <param name="archive" value="physics.jar" />
    <param name="scriptable" value="true" />
    <param name="mayscript" value="true" />
    <param name="file" value="/report_files/1-1272041330710YAIwK" />
</object>
</p>

亲自查看错误的示例页面:http://fogest.com/java_example/ http://fogest.com/java_example/


完整的堆栈跟踪是:

Java Plug-in 10.21.2.11
Using JRE version 1.7.0_21-b11 Java HotSpot(TM) Client VM
User home directory = C:\Users\Andrew
----------------------------------------------------
c:   clear console window
...
0-5: set trace level to <n>
----------------------------------------------------
Trace level set to 5: all ... completed.security: blacklist: hasBeenModifiedSince 1370282598700 (we have 1366432497929)
security: blacklist: hasBeenModifiedSince 1366432497958 (we have 1366432497929)
network: Created version ID: 1.7.0.21
network: Created version ID: 1.7.0.21
basic: exception: java.lang.reflect.InvocationTargetException.
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.runOnEDTAndWait(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.instantiateApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
    at com.sun.deploy.uitoolkit.impl.awt.OldPluginAWTUtil.invokeAndWait(Unknown Source)
    ... 5 more
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 sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkExit(Unknown Source)
    at javax.swing.JFrame.setDefaultCloseOperation(Unknown Source)
    at main.MainGame.run(MainGame.java:36)
    at main.MainGame.<init>(MainGame.java:31)
    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 com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$1.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$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)
basic: Removed progress listener: sun.plugin.util.ProgressMonitorAdapter@1f312f0
security: Reset deny session certificate store
security: blacklist: hasBeenModifiedSince 1366740392097 (we have 1366432497929)
security: blacklist: hasBeenModifiedSince 1369035157319 (we have 1366432497929)
network: CleanupThread used 6369043 us
basic: PluginMain.unregisterApplet: 1 from mananger sun.plugin2.applet.Applet2Manager@1823290
network: Checking for update at: https://javadl-esd-secure.oracle.com/update/baseline.version
network: Checking for update at: https://javadl-esd-secure.oracle.com/update/blacklisted.certs
network: Checking for update at: https://javadl-esd-secure.oracle.com/update/blacklist
security: JSS is not configured
network: Connecting https://javadl-esd-secure.oracle.com/update/baseline.version with proxy=DIRECT
network: Connecting https://javadl-esd-secure.oracle.com/update/blacklisted.certs with proxy=DIRECT
network: Connecting https://javadl-esd-secure.oracle.com/update/blacklist with proxy=DIRECT
network: Connecting http://javadl-esd-secure.oracle.com:443/ with proxy=DIRECT
network: Connecting http://javadl-esd-secure.oracle.com:443/ with proxy=DIRECT
network: Connecting http://javadl-esd-secure.oracle.com:443/ with proxy=DIRECT
security: Loading Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
security: Loaded Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
security: Loading SSL Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
security: Loaded SSL Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
security: Loading certificates from Deployment session certificate store
security: Loaded certificates from Deployment session certificate store
security: Loading certificates from Deployment session certificate store
security: Loaded certificates from Deployment session certificate store
security: Loading certificates from Deployment session certificate store
security: Loaded certificates from Deployment session certificate store
network: Cookie service is not available - use cache to determine "Cookie"
network: Cookie service is not available - use cache to determine "Cookie"
network: Cookie service is not available - use cache to determine "Cookie"

重要的部分是:

Caused by: java.security.AccessControlException: access denied 
  ("java.lang.RuntimePermission" "exitVM.0")

这是由于:

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

即使是受信任的小程序也不能(或者至少应该尝试)退出 JVM。

同意 Hovercraft Full Of Eels 的总体主旨,因为这是一个没有被硬塞进小程序的框架。使用启动框架Java网络启动 https://stackoverflow.com/tags/java-web-start/info.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

小程序中的 java.lang.reflect.invocacytargetexception 错误 [已关闭] 的相关文章

随机推荐

  • Firebase 存储 – 无法根据大小要求删除

    我想允许用户只将文档上传到自己的存储桶中 最大文件大小为1MB 并且仍然允许他们删除文件 我添加了以下内容 match myusers userId allPaths allow write if request auth uid user
  • 获取 WebException 错误中的错误号

    如何获取WebException错误中的错误号 try HttpWebRequest request HttpWebRequest HttpWebRequest Create site HttpWebResponse response Ht
  • 跳转后 vim 中自动 'zz'

    当我跳转到世界上的任何地方后 无论是在当前文件还是在不同的文件中 是否可以让vim自动运行zz 重新以当前行为中心 在搜索之类的事情之后我想要这个 ctrl o and ctrl i 以及几乎任何运动 除了hjkl Thanks Voila
  • 不安装jre就运行java?

    正如所问和回答的here https stackoverflow com questions 2678702 install python 2 6 without using installer on win32 python 有一种无需安
  • 为什么在VS2010中添加服务引用时,没有生成客户端类?

    我快要疯了 我相信 也就是说 我以前从未遇到过这样的问题 而且似乎没有人 Google 已索引 遇到同样的问题 每当我向 VS2010 项目添加对特定 ASMX 服务的引用时 都会生成所有代码 并且有一个接口ServiceSoap它代表了服
  • 二维数组指针和 *arr[] 有什么区别?

    我试图理解这样的数组之间有什么区别 int arr 2 2 0 1 2 3 int pArr int arr for int i 0 i lt 4 i printf d pArr i 和这个 int foo 2 arr1 arr2 Let
  • null 和空字符串之间的区别[重复]

    这个问题在这里已经有答案了 空字符串 String s null 和一个空字符串 String s 这就是我所拥有的 String s1 print statement does not print any thing for s1 but
  • Haskell 如何创建 Word8?

    我想写一个简单的函数来分割ByteString into ByteString using n 作为分隔符 我的尝试 import Data ByteString listize ByteString gt ByteString listi
  • jQuery .ajax() 与 jsonp 不调用成功回调函数

    我有一个 facebook iframe 应用程序 它向我的服务器发出跨域请求并请求 JSONP 格式的数据 这是我的客户端代码 jQuery ajax url type post data method set user prizes d
  • 为什么 Python 不允许在其定义中引用类?

    Python 3 和 2 不允许您在其主体内引用类 方法中除外 class A static attribute A 这就提出了一个NameError在第二行 因为 A is not defined 而这 class A def metho
  • MPMoviePlayerViewController 无法在 iOS 7 上运行

    我有一个在 iOS 7 之前有效的代码 更新后电影无法播放 void setMovie NSURL newMovie autoPlay BOOL autoPlay movieView MPMoviePlayerViewController
  • 检测 JSplitPane 分隔线移动

    有没有办法检测 JSplitPane 分隔线何时移动 有没有办法为分隔线移动添加监听器 JPanel panel1 new JPanel JPanel panel2 new JPanel JSplitPane sp new JSplitPa
  • 如何在orders、ordersDetails模式中保存、处理订单总金额?

    几个月前 当我开始设计应用程序数据库模式时 我被告知不要存储相同的数据 计算数据数据库中的多个位置 规范化 如果我这样做 当我在一个地方更新数据而在另一个地方不更新时 我会产生一系列错误 所以我做了一个订单表和订单详细信息表 像这样的东西
  • XPath 适合 HTML5 格式吗?

    我们知道XPath是为XML解析而创建的 HTML5 怎么样 因为它不一定遵守 XML 规则 有 2 种 XML 词法 XML 和解析 XML XPath 针对解析的 XML 表示形式工作 例如 DOM 或XDM http www w3 o
  • 服务器发送 200:OK 时 Backbone model.save 返回错误

    我定义了以下骨干模型 var User Backbone Model extend url login contentType application com example auth json defaults userName pass
  • PHP中的while循环问题

    我的标记结构如下 div div value1 div div value2 div div value3 div div value4 div div class clear div div div div value5 div div
  • ASP.NET 2.0 网站可以引用 WCF Web 服务吗?

    我们公司目前有一个网站部署在Windows 2000操作系统中 这意味着我们只能在该机器上安装 NET 2 0 升级网络服务器操作系统是不可能的 因为该网络服务器还托管我们国家的其他网络应用程序 作为我们 IT 政策的一部分 出于安全原因
  • 在内容级别与 google chrome 扩展一起使用时,未定义 DP_jQuery_*

    我正在开发一个谷歌浏览器扩展 我正在尝试在现有网页 内容级别 的 jquery ui 对话框中使用 jquery ui datepicker 就像这样 截屏 http sites google com site kamimark files
  • 如何获取最近经过身份验证的用户?

    我正在使用 MVC 3 并且刚刚实现了 FormsAuthenticationService 的包装器 类似于以下内容 public void SignIn string username bool createPersistantCook
  • 小程序中的 java.lang.reflect.invocacytargetexception 错误 [已关闭]

    这个问题不太可能对任何未来的访客有帮助 它只与一个较小的地理区域 一个特定的时间点或一个非常狭窄的情况相关 通常不适用于全世界的互联网受众 为了帮助使这个问题更广泛地适用 访问帮助中心 help reopen questions 我的应用程