2013-04-15 39 views
0

嗨外墜毀我有一個小問題,JavaFXs DragandDrop(DND)JavaFX的拖放將使Java虛擬機

免打擾正確執行,這意味着在文件被創建並移動到右側posiotion。即使我使用現有文件(然後我不創建新文件),該文件也會正確移動內容。

下面是代碼行:

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(); 
     } 
    }); 
} 

但event.consume()之後,我的JVM崩潰和程序與錯誤結束:

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

回答

0

我已經試過YOUT代碼但對我來說它是有效的。
也許你(或你vm)在這個文件夾上沒有寫權限。

也許使用的

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

代替

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

能否請您發佈一個完整的代碼示例,這樣我可以試試這絲毫?

+0

謝謝你,我已經改變了它,但問題的存在。我附上了一個完整的代碼示例。也許這是「新手JDKs」的問題 – worcin

+0

您使用的是哪個jdk? – worcin

0

這裏是fullcode,例如,FYI我使用jdk2.17和Windows7,出現該問題在3個不同(窗口)的機器

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); 
    } 
}