gpt4 book ai didi

java - SwingWorker 抛出异常

转载 作者:行者123 更新时间:2023-11-29 05:53:48 25 4
gpt4 key购买 nike

我正在尝试在 TransferHandler 类的 importData(..) 方法中使用 SwingWorker(以支持拖放) .我想显示我拖动的文件的导入进度。但是,它不起作用。我不明白问题是什么,或者是什么原因造成的。

private class FileImportTransferHandler extends TransferHandler {

@Override
public boolean importData(JComponent comp, final Transferable t) {

SwingWorker<Void, String> worker = new SwingWorker<Void, String>() {

@Override
protected Void doInBackground() throws Exception {
//When commenting this code it and everything else it doesn't
DataFlavor[] flavors = t.getTransferDataFlavors(); //<---- throws exception
//..more code that doesn't run.
}

@Override
protected void done() {
super.done();

try {
get();
} catch (InterruptedException ex) {
Logger.getLogger(ImportBeanController.class.getName()).log(Level.SEVERE, null, ex);
} catch (ExecutionException ex) {
Logger.getLogger(ImportBeanController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
//Starting worker etc here.
}
}

异常(exception):

java.util.concurrent.ExecutionException: java.lang.NullPointerException at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222) at java.util.concurrent.FutureTask.get(FutureTask.java:83) at javax.swing.SwingWorker.get(SwingWorker.java:582) at com.jatech.app.controllers$ImportBeanController$1.done(ImportBeanController.java:158) at javax.swing.SwingWorker$5.run(SwingWorker.java:717) at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(SwingWorker.java:814) at sun.swing.AccumulativeRunnable.run(AccumulativeRunnable.java:95) at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(SwingWorker.java:824) at javax.swing.Timer.fireActionPerformed(Timer.java:291) at javax.swing.Timer$DoPostEvent.run(Timer.java:221) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641) at java.awt.EventQueue.access$000(EventQueue.java:84) at java.awt.EventQueue$1.run(EventQueue.java:602) at java.awt.EventQueue$1.run(EventQueue.java:600) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.awt.EventQueue.dispatchEvent(EventQueue.java:611) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) Caused by: java.lang.NullPointerException at sun.awt.dnd.SunDropTargetContextPeer.getTransferDataFlavors(SunDropTargetContextPeer.java:176) at sun.awt.datatransfer.TransferableProxy.getTransferDataFlavors(TransferableProxy.java:48) at java.awt.dnd.DropTargetContext$TransferableProxy.getTransferDataFlavors(DropTargetContext.java:327)

最佳答案

关于java - SwingWorker 抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12935568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com