0

Hi I have a small problem with JavaFXs DragandDrop(DnD)

The DnD is executed correctly, which means the file is created and moved to the right posiotion. Even if I use an existing file (then i don't create a new file), the file is correctly moved with content.

Here are the line of Code:

    void setupGestureSource(final Text source) {
    source.setOnDragDetected(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            Vector<File> vec = new Vector<File>();
            Dragboard db = source.startDragAndDrop(TransferMode.ANY);
            File tmpFile = new File("test.txt");
            try {
                tmpFile.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            vec.add(tmpFile);
            ClipboardContent content = new ClipboardContent();
            content.putFiles(vec);
            db.setContent(content);
            event.consume();
        }
    });
}

But after the event.consume() my JVM crashes and the program ends with the error:

java.lang.NullPointerException
at com.sun.javafx.tk.quantum.QuantumToolkit$14.actionPerformed(QuantumToolkit.java:1154)
at com.sun.glass.ui.Clipboard.actionPerformed(Clipboard.java:139)
at com.sun.glass.ui.win.WinDnDClipboard.push(Native Method)
at com.sun.glass.ui.win.WinSystemClipboard.pushToSystem(WinSystemClipboard.java:213)
at com.sun.glass.ui.SystemClipboard.flush(SystemClipboard.java:28)
at com.sun.glass.ui.ClipboardAssistance.flush(ClipboardAssistance.java:34)
at com.sun.javafx.tk.quantum.QuantumClipboard.flush(QuantumClipboard.java:197)
at com.sun.javafx.tk.quantum.QuantumToolkit.startDrag(QuantumToolkit.java:1195)
at javafx.scene.Scene$DnDGesture.dragDetectedProcessed(Scene.java:2652)
at javafx.scene.Scene$DnDGesture.process(Scene.java:2713)
at javafx.scene.Scene$DnDGesture.access$8700(Scene.java:2607)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3344)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3168)
at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3123)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1563)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2265)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:250)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:173)
at java.security.AccessController.doPrivileged(Native Method)#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_UNCAUGHT_CXX_EXCEPTION (0xe06d7363) at pc=0x74efc41f, pid=6592, tid=6596
#
# JRE version: 7.0_17-b02
# Java VM: Java HotSpot(TM) Client VM (23.7-b01 mixed mode, sharing windows-x86 )
# Problematic frame:
# C  [KERNELBASE.dll+0xc41f]
    at 

com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:292)
at com.sun.glass.ui.View.handleMouseEvent(View.java:528)
at com.sun.glass.ui.View.notifyMouse(View.java:922)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
at java.lang.Thread.run(Thread.java:722)
Exception in thread "JavaFX Application Thread" Error: 80de0001 in checkJavaException(env) RaiseException+0x58
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\Apfelmaennchen\workspace\asd\hs_err_pid6592.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
4

2 回答 2

0

我试过你的代码,但对我来说它有效。
也许您(或您的 vm)对此文件夹没有写权限。

也许使用

List<File> list = new ArrayList<>();

代替

Vector<File> vec = new Vector<File>();

您能否发布一个完整的代码示例,以便我可以试试这个?

于 2013-04-18T06:16:43.690 回答
0

这是完整的代码示例,仅供参考,我使用的是 jdk2.17 和 windows7,问题出现在 3 个不同的(windows)机器上

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Test App");
        Group rootGroup = new Group();
        Scene scene = new Scene(rootGroup);
        Text text = new Text(100,100,"Drag For new file");
        rootGroup.getChildren().add(text);
        setupGestureSource(text);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    void setupGestureSource(final Text source) {
        source.setOnDragDetected(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                List<File> vec = new ArrayList<File>();
                Dragboard db = source.startDragAndDrop(TransferMode.ANY);
                File tmpFile = new File("test.txt");
                try {
                    tmpFile.createNewFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                vec.add(tmpFile);
                ClipboardContent content = new ClipboardContent();
                content.putFiles(vec);
                db.setContent(content);
                event.consume();
            }
        });
    }

    public static void main(String[] args) {
        launch(args);
    }
}
于 2013-04-18T14:02:30.590 回答