在程序运行时有如下信息:
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);
      JTextArea filetext=new JTextArea();
      final JComboBox fileCombo=new JComboBox();
       fileCombo.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent event){
        loadZipFile((String)fileCombo.getSelectedItem());
        }
       });
       add(fileCombo,BorderLayout.SOUTH);
       add(new JScrollPane(filetext),BorderLayout.CENTER);
}
private class OpenAction implements ActionListener
{
public void actionPerformed(ActionEvent event){
JFileChooser chooser=new JFileChooser();
chooser.setCurrentDirectory(new File("."));
ExtensionFileFilter filter=new ExtensionFileFilter();
filter.addExtension(".zip");
filter.addExtension(".jar");
filter.setDescription("ZIP archives");
chooser.setFileFilter(filter);
int r=chooser.showOpenDialog(ZipTestFrame.this);
if(r==JFileChooser.APPROVE_OPTION){
 zipname = chooser.getSelectedFile().getPath();
scanZipFile();
}
}

}
public void scanZipFile()
{

fileCombo.removeAllItems();
try
{
ZipInputStream zin=new ZipInputStream(new FileInputStream(zipname));
ZipEntry entry;
while((entry=zin.getNextEntry())!=null);
{
fileCombo.addItem(entry.getName());
zin.closeEntry();
}
zin.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
public void loadZipFile(String name)
{
try
{

ZipInputStream zin=new ZipInputStream(new FileInputStream(zipname));
ZipEntry entry;
filetext.setText("");
while((entry=zin.getNextEntry())!=null)
{
if(entry.getName().equals(name))
{
BufferedReader in=new BufferedReader(new InputStreamReader(zin));
String line;
while((line=in.readLine())!=null)
{
filetext.append(line);
filetext.append("\n");
}
}
zin.closeEntry();
}
zin.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
private JComboBox fileCombo;
private JTextArea filetext;
private String zipname;
}
class ExtensionFileFilter extends FileFilter
{
public void addExtension(String extension)
{
if(!extension.startsWith("."));
extension="."+extension;
extensions.add(extension.toLowerCase());
}
public void setDescription(String aDescription)
{
description=aDescription;

}
public String getDescription()
{
return description;
}
public boolean accept(File f)
{
if(f.isDirectory()) return true;
String name=f.getName().toLowerCase();
for(String e:extensions)
if (name.endsWith(e))
return true;
return false;
}
private String description="";
private ArrayList<String> extensions=new ArrayList<String>();
}
希望高手们帮帮忙!!我弄了很久了 不得其解!!