Can't get tables demo to run in Processing 3.0 using example from reference

https://processing.org/reference/Table.html

...provides an example of how to create a table in Processing. In Processing 2.0, I was able to successfully have data persist in an android application area, not requiring external storage permission, within the Data folder. However, with Processing 3.0, I cannot get anything to save and reload and cannot test my old code against android 2.x because the current version of 2.x available for download (2.2.1 I believe) has android mode disabled.

Here is an example. I took the example code from the reference, and reduced it further in an attempt to figure out what is going in in 3.0. No Joy despite over a week of futzing with this and loadStrings, saveStrings, loadTable, saveTable, and a seemingly infinite number of possible locations for data files.

I have come to conclude that load and save of strings and tables needs updated documentation, or there is a bug.

Common themes of the errors I have encountered: if saveTable

1) example documentation that includes file names with prefix of "data/" but error message that says "invalid; path separator cannot be used".

2) crash in animation string.

Here is an example: If saveTable is not commented out, the stacktrace at the bottom is generated.

****Can anyone provide a working example of loadString / saveString, or loadTable / saveTable, along with associated directory structure and example file?****

Thank you Joe Miller Tucson

Table table; int xint=0; String xstring;

void setup() {

table = new Table(); xstring = "0"; xint = int(xstring);

table.addColumn("id"); table.addColumn("x");

TableRow newRow = table.addRow(); newRow.setInt("id", table.lastRowIndex()); newRow.setString("x", xstring);

saveTable(table, "data/tabledemo.csv"); }

void draw() { println(xint); xint=xint+1; }

/* FATAL EXCEPTION: Animation Thread Process: processing.test.tabledemo, PID: 4624 java.lang.IllegalArgumentException: File data/tabledemo.csv contains a path separator at android.app.ContextImpl.makeFilename(ContextImpl.java:2288) at android.app.ContextImpl.getFileStreamPath(ContextImpl.java:1079) at android.content.ContextWrapper.getFileStreamPath(ContextWrapper.java:195) at processing.core.PApplet.sketchPath(Unknown Source) at processing.core.PApplet.savePath(Unknown Source) at processing.core.PApplet.saveFile(Unknown Source) at processing.core.PApplet.saveTable(Unknown Source) at processing.core.PApplet.saveTable(Unknown Source) at processing.test.tabledemo.tabledemo.setup(tabledemo.java:36) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source) at processing.core.PApplet.run(Unknown Source) at java.lang.Thread.run(Thread.java:841) */

Answers

  • number 1 - a complaint that you don't like my font selection number 2 - a dead link. not sure how this answers the question but thank you anyway.

  • edited July 2016

    Fixed link. It wasn't GitHhub but GitHub.
    And it's not anything 'bout font but posting proper formatted code in this forum! :(|)

  • Answer ✓

    File data/tabledemo.csv contains a path separator

    This looks to be the problem. Get rid of the data/ from the start of the filename.

  • edited July 2016

    Thank you GoToLoop and koogs

    CTRL+o used to format code the following works as an example of code that

    a) look for a table to initialize a variable xint;

    b) if the table does not exist, for example after a first install, create the table and initialize x with a desired first run value

    c) after each draw(), updates x in the table;

    d) should the android activity lose focus, when onResume is called, and draw() resumes, the prior value of x is restored.

    I hope this is helpful to others and thank GoToLoop and koogs for the advice. I can't say where in the Processing development environment to put a handcrafted initialization file, the above example avoids this by creating the table and letting the system calls decide where to put this.

    I hope this is helpful to others and thank GoToLoop and koogs for the advice.

    Final question: do I post a bug report so the processing reference can be updated?

    PocoJoe

    //////////////////////////////////////////////////////////////////// 
    // demo of use of table to buffer values of a variable that can be later restored 
    // when activity focus is regained 
    // processing 3.0 
    // pocojoe 7/16/2016 
    ///////////////////////////////////////////////////////////////////
    
    Table table;
    int xint=0;
    
    void setup() {
    }
    
    void draw() {
      xint = 0;
      try {
        table  = loadTable("tabledemo.csv","header");
      } catch (Exception e) {
        println(e.toString());
        //e.printStackTrace();
        table = null;
      }
      if (table == null) {
        // Stop reading because of an error or file is empty
        println("need to initialize table"); 
        table = new Table();
        xint = 0;
        table.addColumn("x int");
        TableRow newRow = table.addRow();
        newRow.setInt("x int", xint); 
        saveTable(table, "tabledemo.csv");
      }
      xint = table.getInt(0,"x int");
      println(xint);
      xint=xint+1;
      table.setInt(0,"x int",xint);
      saveTable(table, "tabledemo.csv");
    }
    
Sign In or Register to comment.