Program freezes on loadTable()

edited June 2017 in Questions about Code

The following program appears to freeze on the loadTable() line. I can get the program to work fine in debugger mode by stepping through the code but it does not seem to want to execute properly with the normal run mode.

Table dotdata;
String filepath="";
String savefilepath="";
int columncount= 0;
int rowcount=0;

void setup() {
  size(500, 500);
  background(0);
  dotdata=new Table();
}

void draw() {
  selectInput("Select .txt file", "fileSelected");

  while (filepath=="") {
  };

  dotdata = loadTable(filepath, "tsv");
  print("hello");

  for (int i=0; i<7; i++) {
    dotdata.removeRow(0);
  }
  dotdata.removeColumn(5);
  dotdata.removeColumn(4);
  dotdata.removeColumn(1);
  dotdata.removeColumn(0);

  dotdata.addColumn();
  dotdata.addColumn();
  dotdata.addColumn();

  //int columncount= dotdata.getColumnCount();
  int rowcount=dotdata.getRowCount();


  for (int i=0; i<rowcount; i++) {
    dotdata.setFloat(i, 2, dotdata.getFloat(i, 0)+150);
    dotdata.setFloat(i, 3, dotdata.getFloat(i, 1)-150);
  }

  for (int i=0; i<rowcount; i++) {
    dotdata.setString(i, 4, str(dotdata.getFloat(i, 2)) + "," + str(dotdata.getFloat(i, 3)));
  }

  filepathnaming();

  saveTable(dotdata, savefilepath);
  exit();
}



void fileSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
    exit();
  } else {
    filepath=selection.getAbsolutePath();
  }
}

void filepathnaming() {
  savefilepath="";
  String[] filepathlist = split(filepath, "\\");

  for (int i=0; i<filepathlist.length-1; i++) {
    savefilepath +=filepathlist[i]+ "\\";
  }

  savefilepath += filepathlist[filepathlist.length-1].substring(0, filepathlist[filepathlist.length-1].indexOf(".txt"))+"_update.csv";

  println(savefilepath);
}

Answers

  • Go back

    Edit your post

    Format code correctly: empty lines before and after code section

    Select code

    Hit ctrl-o or the C sign in the small command bar

  • Maybe instead of while use

    if(!filepath.equals("") ) { ......

    because draw loops automatically

    Also, equality with strings: better use .equals("")

  • @Chrisir

    I tried your suggestions but I am still having the same issue. The while loop is there to wait until the user has finished inputting the file with selectInput().

    Also note, the code works fine in debug mode if I step through the code.

  • @Chrisir

    I also get the following error message in the console when the code executes properly in Debug mode.

    Exception in thread "AWT-EventQueue-0" com.sun.jdi.VMDisconnectedException: Got IOException from Virtual Machine at org.eclipse.jdi.internal.connect.PacketSendManager.sendPacket(PacketSendManager.java:90) at org.eclipse.jdi.internal.MirrorImpl.requestVM(MirrorImpl.java:187) at org.eclipse.jdi.internal.MirrorImpl.requestVM(MirrorImpl.java:227) at org.eclipse.jdi.internal.MirrorImpl.requestVM(MirrorImpl.java:243) at org.eclipse.jdi.internal.StringReferenceImpl.value(StringReferenceImpl.java:57) at processing.mode.java.debug.VariableNode.getStringValue(VariableNode.java:96) at processing.mode.java.VariableInspector$ValueCellRenderer.getTableCellRendererComponent(VariableInspector.java:626) at javax.swing.JTable.prepareRenderer(JTable.java:5723) at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2114) at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:2016) at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1812) at javax.swing.plaf.ComponentUI.update(ComponentUI.java:161) at javax.swing.JComponent.paintComponent(JComponent.java:780) at javax.swing.JComponent.paint(JComponent.java:1056) at javax.swing.JComponent.paintToOffscreen(JComponent.java:5210) at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1579) at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1502) at javax.swing.RepaintManager.paint(RepaintManager.java:1272) at javax.swing.JComponent._paintImmediately(JComponent.java:5158) at javax.swing.JComponent.paintImmediately(JComponent.java:4969) at javax.swing.RepaintManager$4.run(RepaintManager.java:831) at javax.swing.RepaintManager$4.run(RepaintManager.java:814) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:789) at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:738) at javax.swing.RepaintManager.access$1200(RepaintManager.java:64) at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1732) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:726) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

  • Answer ✓

    I understood why you use while but I think it's not a good idea

    also == doesn't work on String

    This seems to work:

    Table dotdata;
    String filepath="";
    String savefilepath="";
    int columncount= 0;
    int rowcount=0;
    
    void setup() {
      size(500, 500);
      background(0);
      dotdata=new Table();
    
      selectInput("Select .txt file", "fileSelected"); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!
    }
    
    void draw() {
    
      if (!filepath.equals("")) {  // !!!!!!!!!!!!!!!!!
    
        dotdata = loadTable(filepath, "tsv");
        //  print("hello");
    
        TableRow r1=dotdata.getRow(0); 
    
        println(r1.toString());
    
    
        for (int i=0; i<7; i++) {
          dotdata.removeRow(0);
        }
        dotdata.removeColumn(5);
        dotdata.removeColumn(4);
        dotdata.removeColumn(1);
        dotdata.removeColumn(0);
    
        dotdata.addColumn();
        dotdata.addColumn();
        dotdata.addColumn();
    
        //int columncount= dotdata.getColumnCount();
        int rowcount=dotdata.getRowCount();
    
    
        for (int i=0; i<rowcount; i++) {
          dotdata.setFloat(i, 2, dotdata.getFloat(i, 0)+150);
          dotdata.setFloat(i, 3, dotdata.getFloat(i, 1)-150);
        }
    
        for (int i=0; i<rowcount; i++) {
          dotdata.setString(i, 4, str(dotdata.getFloat(i, 2)) + "," + str(dotdata.getFloat(i, 3)));
        }
    
        filepathnaming();
    
        saveTable(dotdata, savefilepath);
        exit();
      }
    } 
    
    void fileSelected(File selection) {
      if (selection == null) {
        println("Window was closed or the user hit cancel.");
        exit();
      } else {
        filepath=selection.getAbsolutePath();
      }
    }
    
    void filepathnaming() {
      savefilepath="";
      String[] filepathlist = split(filepath, "\\");
    
      for (int i=0; i<filepathlist.length-1; i++) {
        savefilepath +=filepathlist[i]+ "\\";
      }
    
      savefilepath += filepathlist[filepathlist.length-1].substring(0, filepathlist[filepathlist.length-1].indexOf(".txt"))+"_update.csv";
    
      println(savefilepath);
    }
    ///
    
Sign In or Register to comment.