我的应用程序作为一个应用程序运行时没有错误,但是作为一个applet引发了以下错误:
java.lang.reflect.invocationtargetexception
这是我第一次尝试将应用程序用作applet,因此我可能做错了一些,但这是我的主要课程:
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/
完整的堆栈跟踪为:
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);
甚至没有一个受信任的applet也不能(或者至少应该尝试)退出JVM。
问题内容: Java applet代码 html文件 错误 问题答案: 问题出在包装上。您需要更改applet的code属性,并根据放置HTML的位置更改codebase属性。您必须将HellowApplet.class放在名为M257Applet的目录中(因为这是您提供的软件包),并且applet标记应类似于: 为此,您的HTML必须与M257Applet位于同一目录(不在M257Applet内
问题内容: 我有使用jna指针类的小程序。小程序代码为: 在html代码中,我以这种方式声明了applet: 当我通过JavaScript调用document.getElementById(“ Applet1”)。test()时,会出现java.lang.reflect.InvocationTargetException。我无法在Java类端调用e.getCause(),因为applet try
问题内容: 我有一些非平凡的计算代码,它们需要应用于已经下载到浏览器DOM中并从用户交互中捕获的数据。我不想公开此代码。我想知道是否: 编写Web服务,并通过WebSocket或HTTP与浏览器通信。需要权衡的是交互速度(从流畅到差)和更高的流量成本。 编写一个Java小程序(签名以隐藏代码),该小程序将逻辑封装在页面内,并使JavaScript与Java API进行交互。我在其他地方读到Java
问题内容: 我创建了一个Java applet(.class文件),并用它制作了一个.jar并对该.jar文件进行了数字签名。现在我需要将.jar作为小程序运行在Firefox中。我要在html代码中放入什么以将.jar文件作为applet运行?我尝试了一下,但它不起作用,它尝试获取.class文件,如何使用Internet Explorer和Firefox中的applet标签将applet加载并
Groovy版本:Groovy版本:3.0.0-rc-3 JVM:1.8。0_221供应商:Oracle Corporation OS:Linux 运行命令时:groovysh错误输出:
问题内容: 我使用Eclipse创建了一个applet: 此小程序需要两个外部jar:proj.jar和firebirdsql-full.jar(jdbc) 因此,我在罐子所在的文件夹中创建了这样的HTML: 我也尝试更改属性中的jar顺序。 但是我继续收到以下错误(在Java控制台中): 我想念什么吗? 编辑: 不知何故,在调试时,我还收到了另一个堆栈跟踪: 问题答案: 现在我们看到了第二个堆栈