title: JavaFX listView on-drag list items of type int[] ( Java Messsge:-1 )
body: <p>So i have quite a hard task of making my listview items dragable so i can change theyr index , items in listview are <strong>int[]</strong> so i use <code>CustomWeaponRecoilRowListCell&lt;T&gt; extends ListCell&lt;T&gt;</code>  with <strong></strong> param since i dont want to encapsulate my int[] in some object and i cant get any int array class to put there/there is none.</p>
  
  <p>I follow amazing answer from Jewelsea <a href="https://stackoverflow.com/questions/20412445/how-to-create-a-reorder-able-tableview-in-javafx">How to create a reorder-able TableView in JavaFx</a></p>
  
  <p>My first attempt was :</p>
  
  <pre><code>public class CustomWeaponRecoilRowListCell&lt;T&gt; extends ListCell&lt;T&gt; {
  
      private final StringBuilder sb = new StringBuilder();
  
      public CustomWeaponRecoilRowListCell() {
  
          setOnDragDetected((MouseEvent event) -&gt; {
              if (getItem() == null) {
                  return;
              }
              ObservableList&lt;T&gt; items = (ObservableList&lt;T&gt;) getListView().getItems();
  
              Dragboard dragboard = startDragAndDrop(TransferMode.MOVE);
              ClipboardContent content = new ClipboardContent();
  
              content.putString(CsgoRr.objectToJsonString(getItem()));
  
              dragboard.setDragView(textToImage(CsgoRr.objectToJsonString(getItem())));
  
              dragboard.setContent(content);
              event.consume();
          });
  
          setOnDragOver(event -&gt; {
              if (event.getGestureSource() != this
                      &amp;&amp; event.getDragboard().hasString()) {
                  event.acceptTransferModes(TransferMode.MOVE);
              }
              event.consume();
          });
  
          setOnDragEntered(event -&gt; {
              if (event.getGestureSource() != this
                      &amp;&amp; event.getDragboard().hasString()) {
                  setOpacity(0.3);
              }
          });
  
          setOnDragExited(event -&gt; {
              if (event.getGestureSource() != this
                      &amp;&amp; event.getDragboard().hasString()) {
                  setOpacity(1);
              }
          });
  
          setOnDragDropped(event -&gt; {
              if (getItem() == null) {
                  return;
              }
  
              Dragboard db = event.getDragboard();
              boolean success = false;
  
              if (db.hasString()) {
                  ObservableList&lt;T&gt; items = getListView().getItems();
  
                  int draggedIdx = items.indexOf(db.getString());
                  int thisIdx = items.indexOf(getItem());
  
                  items.set(draggedIdx, getItem());
                  items.set(thisIdx, jsonRowStringToT(db.getString()));
  
                  List&lt;T&gt; itemscopy = new ArrayList&lt;&gt;(getListView().getItems());
                  getListView().getItems().setAll(itemscopy);
  
                  success = true;
              }
              event.setDropCompleted(success);
  
              event.consume();
          });
  
          setOnDragDone(DragEvent::consume);
      }
  
      private T jsonRowStringToT(String jsonRow) {//take care of possible exceptions
  
          String[] row = jsonRow.replace("]", "").replace("[", "").split(",");
          int[] parsedRow = new int[RecoilPattern.PATTERN_WIDTH];
          for (int i = 0; i &lt; RecoilPattern.PATTERN_WIDTH; i++) {
              parsedRow[i] = Integer.valueOf(row[i]);
          }
          return (T) parsedRow;
      }
  
      @Override
      public void updateItem(T item, boolean empty) {
          int[] recoil = (int[]) item;
          super.updateItem(item, empty);
          if (empty) {
              setText(null);
          } else {
              sb.append("[Number of steps:").append(recoil[0]).append(", Pixels per step:").
                      append(recoil[1]).append(", Direction:").append(RecoilPattern.directionToString(recoil[2])).append("]");
  
              setText(sb.toString());
              sb.delete(0, sb.length());
              sb.trimToSize();
          }
      }
  
      private static Image textToImage(String text) {
          Label label = new Label(text);
  
          label.setMinSize(80, 20);
          label.setMaxSize(80, 20);
          label.setPrefSize(80, 20);
          label.setStyle("-fx-background-color: white; -fx-text-fill:black;");
          label.setWrapText(true);
          Scene scene = new Scene(new Group(label));
          WritableImage img = new WritableImage(80, 20);
          scene.snapshot(img);
          return img;
      }
  
  }
  </code></pre>
  
  <p>Which  shows that im dragging i even create image from text of the data that i want to drag,that works  bud all i get into my STACKTRACE is :</p>
  
  <blockquote>
    <p>Java Messsge:-1</p>
  </blockquote>
  
  <p>Thats super useless to me when i try to debug this , <strong>this error is from when i drag and drop list item into another location in listview, no data has changed.</strong></p>
  
  <p><strong>Why do i get this into my console? And no sensible stacktrace that i can work with?</strong></p>
  
  <p>Gif of the problem:</p>
  
  <p><a href="https://i.stack.imgur.com/JCjCI.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JCjCI.gif" alt="enter image description here"></a></p>