我过去几个小时一直试图让这个java小程序在我的网站上运行。当我尝试在我的webhost上运行applet时,我不断收到此错误。 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的链接。
我可以导出这个错误吗?
有什么想法吗?
哦,这是我得到的唯一错误。我会发布所有内容,但是当我点击&#34;详细信息&#34;什么都没有出现。
答案 0 :(得分:0)
由于安全沙箱强加的安全限制,未签名的小程序不会从位于其他主机地址的存档中加载代码。这会导致ExceptionInInitializerError
。
将applet JAR文件移动到applet web主机地址(GoDaddy)或签署applet。
将JAR文件移动到同一主机后的Applet:
<applet code = "render.Render.class" archive = "Babi.jar" width = 1280 height = 720></applet>