import java.applet.*;
import java.awt.*;
public class ShowAnimator extends Applet //shows Exception
{
Image [] m_Images;
int totalImages=14;
int currentImage=0;
public void init()
{
m_Images=new Image[totalImages];
for(int i=0;i<totalImages;i++)
{
m_Images[i]=getImage(getCodeBase(),"images\\img00"+(i+1)+".gif");
}
}
public void start()
{
currentImage=0;
}
public void paint(Graphics g)
{
g.drawImage(m_Images[currentImage],50,50,this);
currentImage=++currentImage%totalImages;
try
{
Thread.sleep(50);
}
catch(Exception e)
{
}
repaint();
}
public static void main(String [] args)
{
Frame f=new Frame("DrawImages");
ShowAnimator s=new ShowAnimator();
f.add(s);
s.init();
f.setSize(200,100);
f.setVisible(true);
}
}
//<applet code="ShowAnimator.class" width=300 height=300>
//</applet>
错误提示如下:
D:\java\lesson6>java ShowAnimator
Exception in thread "main" java.lang.NullPointerException
at java.applet.Applet.getCodeBase(Unknown Source)
at ShowAnimator.init(ShowAnimator.java:13)
at ShowAnimator.main(ShowAnimator.java:38)