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不一样吧!
我认为是其他原因,我运行了removeAll()一点问题都没有。 贴全代码和出错信息
to all: 我怀疑是JVM的原因 在98的IE4.0中运行出现同样异常,在IE5.0中正常 然后在98下安装msJavx86.exe, 问题解决. NT下安装msjavx86.exe居然失败, 以前装过, 应该没问题的 不知大虾们有何看法
Note: clear() is deprecated. As of JDK version 1.1, replaced by removeAll().
clear和removeAll不是一回事吗?
to yangzi:
一个一个清空,是不是指把list中的内容一条一条清除??
我是这样做的,
for(int i=0; i<List.length(); i++)
{
List.remove(i);
}
代替 List.removeAll() 但是好象不行也, NT真是让人苦恼,偏偏希望做的这个东东能跨平台, sigh
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不一样吧!
贴全代码和出错信息
我怀疑是JVM的原因
在98的IE4.0中运行出现同样异常,在IE5.0中正常
然后在98下安装msJavx86.exe, 问题解决.
NT下安装msjavx86.exe居然失败, 以前装过, 应该没问题的
不知大虾们有何看法
{
List.remove(i);
}remove 应该从最大值开始!
//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");//写入文件路径和文件名
}
}
}
}