1234567

请大虾指教一下,我写了个程序,出现了NullPointerException异常。不知怎么解决,代码如下:
import javax.print.DocFlavor.URL;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;


public class Example extends JFrame {
    private JLabel jl=new JLabel();
    private Thread t;
    private int count=0;
    private Container container=getContentPane();
    public Example(){
    setBounds(300,200,250,100);
    container.setLayout(null);
    java.net.URL url=Example.class.getResource("E:\\1.jpeg");
    Icon icon=new ImageIcon(url);//这里有错!!不清楚是什么原因?
    jl.setIcon(icon);
    jl.setHorizontalAlignment(SwingConstants.LEFT);
    jl.setBounds(10,10,200,50);
    jl.setOpaque(true);
    t=new Thread(new Runnable(){
    public void run(){
    while(count<200){
    jl.setBounds(count,10,200,50);
    try{
    t.sleep(1000);
    }catch(Exception e){
    e.printStackTrace();
   
    }
    count+=4;
    if(count==200){
    count=10;
    }
    }
    }
   
    });
    t.start();
    container.add(jl);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
public static void main(String[] args) {
// TODO Auto-generated method stub
           new Example();//这里也是,
}

}
我是新手,正在学习java,请大虾们指教一下:谢谢!

你可能感兴趣的:(thread,.net,swing)