2
我有以下運行的代碼:的getImage與JApplet的
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JPanel;
public class Main extends JApplet{
public static Main instance;
public static ImageIcon getImage(String fname){
return new ImageIcon(instance.getImage(instance.getDocumentBase(),fname));
}
public void init(){
instance = this;
@SuppressWarnings("serial")
JPanel p = new JPanel(){
ImageIcon img = getImage("YES.png");
public void paintComponent(Graphics g){
super.paintComponent(g);
if(img != null)
g.drawImage(img.getImage(),0,0,getWidth(),getHeight(),null);
}
};
this.setContentPane(p);
}
}
當我在eclipse它的工作原理運行此。但是,當我在谷歌上運行了鍍鉻與以下的HTML文檔:
<html>
<head>
<title>VResponse</title>
<style type="text/css">
body{
background-color:white;
padding:1%;
}
</style>
</head>
<body>
<div>
<applet code="Main.class" width="800" height="600" />
</div>
</body>
</html>
我得到下面的空指針異常:
java.lang.NullPointerException
at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
at sun.awt.SunToolkit.getImage(Unknown Source)
at Main.getImage(Main.java:15)
at Main$1.<init>(Main.java:21)
at Main.init(Main.java:20)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
如何解決?
http://vickysoderlund.atspace.cc/ /--- =網頁與誤碼JApplet的上
你應該比布爾在這裏下載整個文件夾: https://drive.google.com/file/d/0B0ng1kJkou-lcUlmWk91bEVXX28/edit?usp=sharing
而SRC代碼是在這裏: https://drive.google.com/file/d/0B0ng1kJkou-lYXRERWFnU1czX0k/edit?usp=sharing
你可以發佈堆棧跟蹤嗎? –
Chrome中的地址是什麼? –
@MrD我不知道如何獲得堆棧跟蹤,如果錯誤不是在我在eclipse中運行時發生的。 – csga5000