编程语言
首页 > 编程语言> > Java Web Start小程序/应用程序中的InvocationTargetException

Java Web Start小程序/应用程序中的InvocationTargetException

作者:互联网

作为参考,我之前曾问过一个有关从本质上将Java应用程序转换为applet的错误的问题.好吧,建议我尝试JavaWebStart,但我仍然通过这种方式遇到问题,因此我决定创建一个新问题.

这是我正在参考的问题:java.lang.reflect.invocationtargetexception error in applet

我假设我在某种程度上错误地设置了如何设置JavaWebStart应用程序的结构,因为我已经在本地将我的代码作为jar文件进行了测试,并且没有错误运行它.

这是一个示例页面:
http://fogest.com/java_example/

解决方法:

就像我们在上一个问题中所讨论的那样,您的代码似乎确实具有main(String [] args).这样,它可能像更改一样简单:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="http://fogest.com/java_example" href="">
    <information>
        <title>Launch applet with Web Start</title>
        <vendor>Foo Bar Inc.</vendor>
        <offline-allowed/>
    </information>
    <resources>
        <j2se version="1.5+" href="http://java.sun.com/products/autodl/j2se"/>
        <jar href="physics.jar" main="true" />
    </resources>
    <applet-desc
         name="Physics" main-class="main.MainGame"
         width="300" height="200">
    </applet-desc>
  <update check="background"/>
</jnlp>

像这样:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="http://fogest.com/java_example" href="">
    <information>
        <title>Launch applet with Web Start</title>
        <vendor>Foo Bar Inc.</vendor>
        <offline-allowed/>
    </information>
    <resources>
        <j2se version="1.5+" href="http://java.sun.com/products/autodl/j2se"/>
        <jar href="physics.jar" main="true" />
    </resources>
    <application-desc main-class="main.MainGame">
    </application-desc>
  <update check="background"/>
</jnlp>

注意

>我没有验证任何一个JNLP,但您应该验证.我为此写了JaNeLA.
>应该创建Swing GUI.在美国东部时间更新.有关更多详细信息,请参见Concurrency in Swing(尤其是“初始线程”中的部分).
>这是基于框架的SSCCE.

import java.awt.*;
import javax.swing.*;

public class MainGame {
    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;

    public MainGame() {
        run();
    }

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


        JPanel options = new JPanel();
        options.add(new JLabel("Options"));
        JPanel game = new JPanel();
        game.add(new JLabel("Game"));

        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);
    }

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

标签:applet,java-web-start,invocationtargetexception,java
来源: https://codeday.me/bug/20191123/2065450.html