Hey guys i need some help.. :-/
im trying to add a drag and drop feature to my application. i have found this tutorial: https://docs.oracle.com/javafx/2/drag_drop/jfxpub-drag_drop.htm
its a tutorial to drag and drop a text node. But in my application i have Imageviews.Here is a screenshot of my application. i download 20 photos from flickr und store them in an ImageViewArray.

The User should be able to drag a photo and drop it into these darkgray panes. the screenshot is 1 day old . now i have no Panes there. now i have got empty imageviews.
The difference between my application and the tutorial is that i have got 2 ImageviewArrays! 1 Array for the 20 images i download and 1 array for the 5 empty images views ! i hope this is correct ???BUT this is what i cant handle . it would be awesome if you have got a solution to this. im really desperate i try this for 5 days and its very important. i know my code is a way too cluttered im really new to java. and i know this is not how i should program but please turn a blind eye to this for now.
this is mycode
public class FXMLDocumentController implements Initializable {
String apiKey ="4645765876";
String secret= "7618eb4";
int i = 0;
ArrayList<String> Server = new ArrayList<>();
String eingabe;
PhotoList photoList;
ImageView [] imageview;
Image[] image;
@FXML
Pane pane1,pane2,pane3,pane4,pane5;
@FXML
ImageView i1, i2, i3,i4,i5;
final Pane pane = new Pane();
Pane collage2[]={pane1,pane2,pane3,pane4,pane5};
@FXML
TilePane tile2;
@FXML
ImageView iarray[]={};
@FXML
Button ho;
@FXML
ImageView view;
@FXML
ScrollPane scroll;
@FXML
TilePane tile;
@FXML
TextField text;
@FXML
HBox hobox;
public FXMLDocumentController() {
}
@FXML
private void handleButtonAction(ActionEvent event) throws FlickrException {
tile2 = new TilePane();
// tile2.getChildren().add(bitte);
Flickr flickr = new Flickr (apiKey, secret , new REST());
eingabe = text.getText();
SearchParameters searchParams = new SearchParameters();
String\[\] tags = new String\[\]{eingabe};
String id = new String ();
System.out.println(eingabe);
searchParams.setSort(SearchParameters.INTERESTINGNESS\_DESC);
searchParams.setTags(tags);
searchParams.setUserId(id);
PhotosInterface photoInt = flickr.getPhotosInterface();
photoList = photoInt.search(searchParams,20,1);
if(photoList!=null){
//Get search result and check the size of photo result
for( i=0;i\<photoList.size();i++){
//get photo object
Photo ph =(Photo) photoList.get(i);
Server.add(ph.getLargeUrl());
image = new Image \[Server.size()\];
imageview = new ImageView \[Server.size()\];
image \[i\] = new Image(Server.get(i),true);
imageview\[i\]= new ImageView(image\[i\]);
imageview\[i\].setFitHeight(200);
imageview\[i\].setPreserveRatio(true);
imageview\[i\].setFitWidth(200);
tile.setPadding(new Insets(15, 15, 15, 100));
tile.setHgap(20);
tile.setVgap(17);
tile.getChildren().add(imageview\[i\]);
System.out.println(Server.get(i));
imageview\[i\].setOnDragDetected((MouseEvent event3) -> {
/\* drag was detected, start drag-and-drop gesture\*/
System.out.println("onDragDetected");
/\* allow any transfer mode \*/
Dragboard db = imageview\[i\].startDragAndDrop(TransferMode.MOVE);
ClipboardContent content = new ClipboardContent();
content.putImage(iarray\[i\].getImage());
db.setContent(content);
event3.consume();
});
iarray\[i\].setOnDragOver((DragEvent event4) -> {
/\* data is dragged over the target \*/
System.out.println("onDragOver");
/\* accept it only if it is not dragged from the same node
\* and if it has a string data \*/
if (event4.getGestureSource() != iarray\[i\] &&
event4.getDragboard().hasImage()) {
/\* allow for both copying and moving, whatever user chooses \*/
event4.acceptTransferModes(TransferMode.COPY\_OR\_MOVE);
}
event.consume();
});
tile2.setOnDragEntered((DragEvent event4) -> {
if (event4.getGestureSource() != iarray\[i\] &&
event4.getDragboard().hasImage()) {
System.out.println("was geht");
}
event.consume();
});
iarray\[i\].setOnDragExited((DragEvent event4) -> {
/\* mouse moved away, remove the graphical cues \*/
System.out.println("waaaas");
event4.consume();
});
tile2.setOnDragDropped((DragEvent event4) -> {
/\* data dropped \*/
/\* if there is a string data on dragboard, read it and use it \*/
Dragboard db = event4.getDragboard();
boolean success = false;
if (db.hasString()) {
iarray\[i\].setImage(db.getImage());
success = true;
}
/\* let the source know whether the string was successfully
\* transferred and used \*/
event4.setDropCompleted(success);
event4.consume();
});
}
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
}
}
i think i know that the mistake has something to dowith my iarray[];
i thought that my imageViewArray is the SOURCE because it has the 20 images andthat my iArray is the target because i want DROP the images into the imageViews of this array but something is going really wrong... this is my errorcode
Executing C:\Users\Jens\Documents\NetBeansProjects\Photoview\dist\run453018466\Photoview.jar using platform C:\Program Files\Java\jdk1.8.0_45\jre/bin/java
Jun 18, 2015 4:25:42 AM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
INFO: Could not find stylesheet: jar:file:/C:/Users/Jens/Documents/NetBeansProjects/Photoview/dist/run453018466/Photoview.jar!/style.css
hund
https://farm4.static.flickr.com/3440/3923092674_7a049169c1_b.jpg
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1770)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1653)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8390)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3758)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3486)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2495)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:350)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(GlassViewEventHandler.java:385)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$246/1233629069.get(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:404)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:384)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:927)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/1963387170.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1765)
... 54 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at photoview.FXMLDocumentController.handleButtonAction(FXMLDocumentController.java:168)
... 64 more
this is line 168 in my controller class
iarray[i].setOnDragOver((DragEvent event4) -> {
this is my fxmlcode
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1280.0" stylesheets="@../../style.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="photoview.FXMLDocumentController">
\<children>
\<ScrollPane fx:id="scroll" hbarPolicy="NEVER" layoutX="386.0" layoutY="239.0" prefHeight="542.0" prefWidth="848.0">
\<content>
\<TilePane fx:id="tile" prefHeight="542.0" prefWidth="846.0" />
\</content>
\</ScrollPane>
\<SplitPane dividerPositions="0.5" layoutX="26.0" layoutY="238.0" orientation="VERTICAL" prefHeight="542.0" prefWidth="338.0">
\<items>
\<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
\<children>
\<VBox layoutX="4.0" layoutY="50.0" prefHeight="217.0" prefWidth="336.0" spacing="5.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="50.0">
\<children>
\<Label text="Tags:">
\<font>
\<Font name="Comic Sans MS Bold" size="26.0" />
\</font>
\<VBox.margin>
\<Insets left="35.0" />
\</VBox.margin>
\</Label>
\<HBox prefHeight="36.0" prefWidth="336.0">
\<children>
\<TextField fx:id="text" onAction="#handleButtonAction" />
\</children>
\</HBox>
\<Label text="User-ID">
\<font>
\<Font name="Comic Sans MS Bold" size="26.0" />
\</font>
\<VBox.margin>
\<Insets left="20.0" />
\</VBox.margin>
\</Label>
\<HBox prefHeight="32.0" prefWidth="336.0">
\<children>
\<TextField />
\</children>
\</HBox>
\<Label text="Zeitraum">
\<font>
\<Font name="Comic Sans MS" size="26.0" />
\</font>
\<VBox.margin>
\<Insets left="20.0" />
\</VBox.margin>
\</Label>
\<HBox prefHeight="100.0" prefWidth="200.0" spacing="120.0">
\<children>
\<ComboBox prefWidth="150.0" promptText="24 Stunden" />
\<Button fx:id="button" onAction="#handleButtonAction" text="Click Me!" />
\</children>
\<opaqueInsets>
\<Insets />
\</opaqueInsets>
\<VBox.margin>
\<Insets />
\</VBox.margin>
\</HBox>
\</children>
\</VBox>
\<VBox layoutX="26.0" layoutY="-2.0" prefHeight="51.0" prefWidth="336.0" AnchorPane.bottomAnchor="218.0" AnchorPane.leftAnchor="26.0" AnchorPane.rightAnchor="-26.0" AnchorPane.topAnchor="-2.0">
\<children>
\<Label prefHeight="51.0" prefWidth="182.0" text="Bildersuche">
\<font>
\<Font name="Comic Sans MS Bold" size="26.0" />
\</font>
\</Label>
\</children>
\<padding>
\<Insets left="80.0" />
\</padding>
\</VBox>
\</children>
\</AnchorPane>
\<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
\<children>
\<Label layoutX="79.0" layoutY="5.0" text="Bildbearbeitung">
\<font>
\<Font name="Comic Sans MS Bold" size="26.0" />
\</font>
\</Label>
\<VBox layoutY="46.0" prefHeight="224.0" prefWidth="332.0">
\<children>
\<VBox prefHeight="90.0" prefWidth="332.0">
\<children>
\<Label text="Kontrast">
\<font>
\<Font name="Comic Sans MS Bold" size="26.0" />
\</font>
\</Label>
\<Slider fx:id="kontrast" />
\</children>
\</VBox>
\<VBox prefHeight="200.0" prefWidth="100.0" spacing="20.0">
\<children>
\<Label text="Sättigung">
\<font>
\<Font name="Comic Sans MS Bold" size="26.0" />
\</font>
\</Label>
\<Slider fx:id="saettigung" />
\<VBox prefHeight="200.0" prefWidth="100.0">
\<children>
\<Label text="Helligkeit">
\<font>
\<Font name="Comic Sans MS Bold" size="26.0" />
\</font>
\</Label>
\<Slider fx:id="helligkeit" />
\</children>
\</VBox>
\</children>
\</VBox>
\</children>
\</VBox>
\</children>\</AnchorPane>
\</items>
\</SplitPane>
\<TilePane fx:id="tile2" layoutX="164.0" layoutY="4.0" prefHeight="228.0" prefWidth="1028.0">
\<children>
\<ImageView fx:id="i1" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
\<ImageView fx:id="i2" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
\<ImageView fx:id="i3" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
\<ImageView fx:id="i4" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
\<ImageView fx:id="i5" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
\</children>
\</TilePane>
\</children>
</AnchorPane>
i hope someone can help me its really important
thanks in advance
regards
david