Java1.6打不开文件_java – InterruptedException取消文件打开对话框 – 1.6.0_26

以下代码的输出是:

java.vendor Sun Microsystems Inc.

java.version 1.6.0_26

java.runtime.version 1.6.0_26-b03

sun.arch.data.model 32

os.name Windows XP

os.version 5.1

os.arch x86

Input selection cancelled by user.

Exception while removing reference: java.lang.InterruptedException

java.lang.InterruptedException

at java.lang.Object.wait(Native Method)

at java.lang.ref.ReferenceQueue.remove(Unknown Source)

at java.lang.ref.ReferenceQueue.remove(Unknown Source)

at sun.java2d.Disposer.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

以下代码显示了我的机器上的异常.

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class GUI extends JPanel implements ActionListener {

private final String newline = System.getProperty("line.separator");

JButton openButton;

JTextArea log;

JFileChooser fc;

public GUI() {

super(new BorderLayout());

log = new JTextArea(20,40);

log.setMargin(new Insets(5,5,5,5));

log.setEditable(false);

fc = new JFileChooser();

openButton = new JButton("Open");

openButton.addActionListener(this);

JPanel buttonPanel = new JPanel(); //use FlowLayout

buttonPanel.add(openButton);

add(buttonPanel, BorderLayout.NORTH);

add(new JScrollPane(log));

showProp("java.vendor");

showProp("java.version");

showProp("java.runtime.version");

showProp("sun.arch.data.model");

showProp("os.name");

showProp("os.version");

showProp("os.arch");

}

public void showProp(String name) {

output(name + " \t" + System.getProperty(name));

}

public void output(String msg) {

log.append(msg + newline);

log.setCaretPosition(log.getDocument().getLength());

System.out.println(msg);

}

public void actionPerformed(ActionEvent e) {

//Handle open button action.

int returnVal = fc.showOpenDialog(GUI.this);

if (returnVal == JFileChooser.APPROVE_OPTION) {

//This is where a real application would open the file.

output(

"Input File Selected: " +

fc.getSelectedFile().getName() +

".");

} else {

output("Input selection cancelled by user.");

}

log.setCaretPosition(log.getDocument().getLength());

}

/**

* Create the GUI and show it. For thread safety,

* this method should be invoked from the

* event dispatch thread.

*/

private static void createAndShowGUI() {

//Create and set up the window.

JFrame frame = new JFrame("IDE Output Converter");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Add content to the window.

frame.add(new GUI());

//Display the window.

frame.pack();

frame.setVisible(true);

}

public static void main(String[] args) {

//Schedule a job for the event dispatch thread:

//creating and showing this application's GUI.

SwingUtilities.invokeLater(new Runnable() {

public void run() {

createAndShowGUI();

}

});

}

}

当我运行程序时,主窗口打开,程序运行正常.

但是,如果你:

>使用’打开文件’按钮打开JFileChooser

>按取消然后

>退出程序

抛出InterruptedException.或者如果您选择一个文件并打开它,然后退出程序,则抛出相同的错误.在这个blog上,同样的事情是用示例代码解释的,他的解决方案是调用新的JFileChooser();尽快,我做了没有效果.

这是1.6.0_26的错误吗?如果是这样,那么该版本是否有效?

是代码吗如果是这样,怎么解决呢? (看起来不太可能,还有另外两个空的结果 – 其中一个现在被删除.)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值