1

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

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.
    }       
}

例外:

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) 在 com.jatech.app.controllers$ImportBeanController$1.done(ImportBeanController.java:158) 在 javax.swing.SwingWorker$5.run(SwingWorker.java:717)在 javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(SwingWorker.java:814) 在 sun.swing.AccumulativeRunnable.run(AccumulativeRunnable.java:95) 在 javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(SwingWorker.java:824) 在javax.swing.Timer.fireActionPerformed(Timer.java:291) 在 javax.swing.Timer$DoPostEvent.run(Timer.java:221) 在 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) 在 java.awt.EventQueue$1.run(EventQueue.java:600) 在 java.security.AccessController.doPrivileged(Native Method) 在 java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) 在java.awt.EventQueue.dispatchEvent(EventQueue.java:611) 在 java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) 在 java.awt.EventDispatchThread .pumpEventsForHierarchy(EventDispatchThread.java:174) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java:122) 引起:java.lang.NullPointerException 在 sun.awt.dnd.SunDropTargetContextPeer.getTransferDataFlavors (SunDropTargetContextPeer.java:176) 在 sun.awt.datatransfer.TransferableProxy.getTransferDataFlavors(TransferableProxy.java:48) 在 java.awt.dnd.DropTargetContext$TransferableProxy.getTransferDataFlavors(DropTargetContext.java:327)getTransferDataFlavors(TransferableProxy.java:48) 在 java.awt.dnd.DropTargetContext$TransferableProxy.getTransferDataFlavors(DropTargetContext.java:327)getTransferDataFlavors(TransferableProxy.java:48) 在 java.awt.dnd.DropTargetContext$TransferableProxy.getTransferDataFlavors(DropTargetContext.java:327)

4

1 回答 1

3
于 2012-10-17T13:49:21.760 回答