0

在过去的几个小时里,我一直试图让这个 java 小程序在我的网站上运行。当我尝试在我的虚拟主机上运行小程序时,我不断收到此错误。java.lang.ExceptionInInitializerError

我不懂为什么。我正在使用 GoDaddy 进行网络托管。这是 html 应该运行的类:

package render;

import java.awt.*; 
import java.util.ArrayList;

import scenes.Scene;

import entities.Entity;
import entities.Sprite;
import entities.object.*;
import entities.things.*;

public class Render extends Game{
    private static final long serialVersionUID = 1L;
    public static Image offScreenImage;
    public static Graphics offScreenGraphics;

    public static Dimension window_size = new Dimension(1200,750);


    public void init(){
        this.setPreferredSize(window_size);
        this.setSize(this.getPreferredSize());


        offScreenImage = createImage(this.getWidth(),this.getHeight()); // creates an image of window size
        offScreenGraphics = offScreenImage.getGraphics();   
    }

    public void paint(Graphics g) {
        offScreenGraphics.clearRect(0,0,this.getWidth(),this.getHeight());

        ArrayList<Scene> sro = new ArrayList<Scene>();
        sro.addAll(0, Game.getOverlayScenes()); //sro = scene render order
        sro.add(sro.size(),Game.getScene());

        for (int j=sro.size()-1;j>-1;--j){ // To render scenes in a stack, overlays being over the main scene.

            for (EntityObject i:sro.get(j).objects()){

                    if (i.getVisibility()){

                    if (i.getDrawingType() == Entity.draw_types[0]){
                        Sprite sprite = ((ImageEntity)i).getSprite();
                        try{
                            offScreenGraphics.drawImage(sprite.getImageReference(),(int)sprite.getPosition().getX(),(int)sprite.getPosition().getY(),this);
                        }catch(NullPointerException e){}
                    }else if (i.getDrawingType() == Entity.draw_types[1]){
                        //TODO - Add in text objects
                        //offScreenGraphics.drawString(, x, y);
                    }else if (i.getDrawingType().equals(Entity.draw_types[2])){
                        offScreenGraphics.fillRect((int)i.getPosition().getX(),(int)i.getPosition().getY(),
                                ((Box)i).getRectX(),((Box)i).getRectY());
                    }
                }


            }
        }

        // draws graphics to screen
        g.drawImage(offScreenImage,0,0,this);
     }

    public void update(Graphics g){
        paint(g);
    }
}

和游戏类

package render;

import global.Global;
import input.KeyboardInput;
import input.MouseInput;

import java.applet.Applet;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.Timer;

import resources.ImageLibrary;
import resources.SceneLibrary;
import scenes.Scene;
import scenes.SceneBuilder;
import scenes.more.*;


public class Game extends Applet implements ActionListener{
    private static final long serialVersionUID = 1L;

    private static Timer timer;
    private static int fps = Global.getFPS();

    private static KeyboardInput keyboard = new KeyboardInput();
    private static MouseInput mouse = new MouseInput();

    private static Scene current_scene = new SuperScene();
    private static ArrayList<Scene> overlay_scenes = new ArrayList<Scene>();


    public Game(){
        timer = new Timer(1000/fps,this); // makes timer object that runs 30 times a second
        timer.start();

        ImageLibrary.setupHashMaps();
        SceneLibrary.setupHashMaps();

        SceneBuilder.buildScene(new StartMenu());

        // Keyboard setup
        this.addKeyListener(keyboard); // Window needs to grab the KeyEvents
        // Mouse setup
        this.addMouseListener(mouse);
        this.addMouseMotionListener(mouse);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        EntityUpdater.updateObjects();

        keyboard.poll();
        mouse.poll();

        //repaint - redraws everything
        repaint();

    }

    public static void setScene(Scene scene){
        current_scene = scene;
    }

    public static Scene getScene(){
        return current_scene;
    }

    public static ArrayList<Scene> getOverlayScenes(){
        return overlay_scenes;
    }

    public static void addOverlayScene(Scene scene){
        overlay_scenes.add(scene);
    }

    public static void removeOverlayScene(Scene scene){
        overlay_scenes.remove(scene);
    }


    public static KeyboardInput getKeyboard(){
        return keyboard;
    }

    public static MouseInput getMouse(){
        return mouse;
    }


}

这是html代码:

<html>
<head>
</head>
<body>
<applet code = "render.Render.class" archive = "https://dl.dropboxusercontent.com/u/9279065/Babi.jar" width = 1280 height = 720></applet>

</body>
</html>

您可能会注意到,在 html 代码中,我提供了指向我的 .jar 的链接。

我可以导出这个错误吗?

有任何想法吗?

哦,这是我得到的唯一错误。我会发布所有内容,但是当我单击“详细信息”时,什么都没有出现。

4

1 回答 1

0

由于安全沙箱施加的安全限制,未签名的小程序不会从位于另一个主机地址的存档中加载代码。这会导致ExceptionInInitializerError.

将小程序 JAR 文件移动到小程序 Web 主机地址 (GoDaddy) 或签署小程序。

将 JAR 文件移动到同一主机后的小程序:

<applet code = "render.Render.class" archive = "Babi.jar" width = 1280 height = 720></applet>
于 2013-06-10T01:38:15.037 回答