在程序运行时有如下信息:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at ZipTestFrame.scanZipFile(ZipTest.java:78)
at ZipTestFrame$OpenAction.actionPerformed(ZipTest.java:70)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2013)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2336)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:260)
at javax.swing.AbstractButton.doClick(AbstractButton.java:375)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1689)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1733)
at java.awt.Component.processMouseEvent(Component.java:6100)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3288)
at java.awt.Component.processEvent(Component.java:5865)
at java.awt.Container.processEvent(Container.java:2110)
at java.awt.Component.dispatchEventImpl(Component.java:4461)
at java.awt.Container.dispatchEventImpl(Container.java:2168)
at java.awt.Component.dispatchEvent(Component.java:4287)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4466)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4130)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4060)
at java.awt.Container.dispatchEventImpl(Container.java:2154)
at java.awt.Window.dispatchEventImpl(Window.java:2555)
at java.awt.Component.dispatchEvent(Component.java:4287)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:605)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:276)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:191)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:186)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:178)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:139)
程序如下:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.ArrayList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
public class lianxi {
public static void main(String[] args)
{
ZipTestFrame f=new ZipTestFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
class ZipTestFrame extends JFrame
{
public ZipTestFrame()
{
setTitle("ZipTest");
setSize(100,100);
JMenuBar menuBar=new JMenuBar();
JMenu menu=new JMenu("文件");
JMenuItem menu1=new JMenuItem("打开");
menu1.addActionListener(new OpenAction());
JMenuItem menu2=new JMenuItem("退出");
menu2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event){
System.exit(0);
}
});
menu.add(menu1);
menu.add(menu2);
menuBar.add(menu);
setJMenuBar(menuBar);