这种例外主要是由于list这种数据结构越界所致。奇怪的是你为什么不用clear()方法呢?

解决方案 »

  1.   

    to robber:
    Note: clear() is deprecated. As of JDK version 1.1, replaced by removeAll().
    clear和removeAll不是一回事吗?
    to yangzi:
    一个一个清空,是不是指把list中的内容一条一条清除??
      

  2.   

    是啊,一个一个remove.java有很多莫名其妙的东西。根本没办法解释清楚。
      

  3.   

    to yangzi:
     我是这样做的,
     for(int i=0; i<List.length(); i++)
     {
         List.remove(i);
     }
     代替 List.removeAll()  但是好象不行也, NT真是让人苦恼,偏偏希望做的这个东东能跨平台, sigh
      

  4.   

    to robber:
    Note: clear() is deprecated. As of JDK version 1.1, replaced by removeAll().
    clear和removeAll不是一回事吗?我只是知道在jdk1.3中是支持的,并且not deprecated!!!
    removeAll()已经改成public boolean removeAll(Collection c)
    大概你的jvm不一样吧!
      

  5.   

    我认为是其他原因,我运行了removeAll()一点问题都没有。
    贴全代码和出错信息
      

  6.   

    to all:
    我怀疑是JVM的原因
    在98的IE4.0中运行出现同样异常,在IE5.0中正常
    然后在98下安装msJavx86.exe, 问题解决.
    NT下安装msjavx86.exe居然失败, 以前装过, 应该没问题的
    不知大虾们有何看法
      

  7.   

    for(int i=List.length()-1; i>=0;i--)
    {
        List.remove(i);
    }remove 应该从最大值开始!
      

  8.   

    是applet? 那就都装最新的jre13(比如netscape6带的那个)
      

  9.   

    //用向量试试.
    //vector.removeAllElements();
    //在win98下,用freejava3.0调试
    //希望对你有用
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;public class Test extends JFrame  {
      JList list = new JList();
      JScrollPane sp = new JScrollPane(list);
      Vector data = new Vector();
      JButton button = new JButton("load");
      ButtonListener blistener = new ButtonListener();
      
      public Test(){
      super("Test");
      addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {System.exit(0);}
      });
       list.setVisibleRowCount(10);
       
       button.addActionListener(blistener);   Container contentPane = getContentPane(); 
       contentPane.add(sp,BorderLayout.CENTER);
       contentPane.add(button,BorderLayout.NORTH);   pack();
       setSize(410,300);
       setLocation(200,150);
       setResizable(false);
       setVisible(true);
      }
      public void loadData(String filename) { 
        File inputFile = new File(filename); 
        if (!inputFile.exists()) { 
           try{}
           catch(Exception e){}
        } 
        FileInputStream input = null;
          try { input = new FileInputStream(inputFile); 
          } 
          catch(Exception ioe){ } 
          try { BufferedReader reader = new BufferedReader( new InputStreamReader(input)); 
                if(!data.isEmpty())data.removeAllElements();
                while (true) { 
                    String currentLine = reader.readLine(); 
                    if (currentLine==null) 
                        break; 
                    data.addElement(currentLine); 
                    list.setListData(data);
                }         
          } 
         catch (Exception ioe) { 
         } 
       } 
     public static void main(String args[]) { 
        new Test().show();
     }
     
     class ButtonListener implements ActionListener {
         public void actionPerformed (ActionEvent ae) { 
           Object obj = ae.getSource(); 
           if (obj == button) {loadData("loadtry.txt");//写入文件路径和文件名
        }  
       }
     }
    }