Can a table be created (a csv file) from out of a class instead out of "void setup()" ?

Nothing seems to be written when I look at the csv file in question, no columns are created. But I see no error messages either.


  • I'm not sure what your question means. Can you post an MCVE that demonstrates what you're talking about?

  • edited October 2014


    CSVPreparation InsTCSVPreparation = new CSVPreparation(0);
    void setup()
    InsTCSVPreparation.StartCSV ();
    class CSVPreparation
    int val;
    CSVPreparation( int tempval )
    {val = tempval;}
    void StartCSV ()
    storeData = new Table(); 
    storeData.setString( 1, "A",  "Kether");  
    storeData.setString( 1, "B", "Binnah");  
    }// f
    }// C
  • Word to the wise: you should try to use standard naming conventions: variables and methods should start with lower-case letters.

    Does this code work? What do you expect it to do? What does it do instead? I'm still not sure what your question is...

  • edited October 2014

    It should write a CSV file, thats all. But it doesn't.

  • Where is your storeData variable declared? Does this code compile?

  • edited October 2014 Answer ✓

    Define a class to merely create a Table is a little too much.
    A simpler createCSV() util function is enough IMO: (*)

    // can-a-table-be-created-a-csv-file-
    // from-out-of-a-class-instead-out-of-void-setup-
    final Table table = createCSV();
    void setup() {
      saveTable(table, dataPath("MyTable.csv"));
    static final Table createCSV() {
      Table t = new Table();
      t.setString(0, "A", "Kether");
      t.setString(0, "B", "Binnah");
      t.setString(1, "A", "Frodo");
      t.setString(1, "B", "Chun-Li");
      return t;
    static final void printTable(Table t) {
      String[] titles = new String[t.getColumnCount()];
      for (int i = 0; i != titles.length
        ; titles[i] = t.getColumnTitle(i++));
      int i = 0;
      for (TableRow r : t.rows()) {
        print("[" + i++ + "] - | ");
        for (String s : titles)
          print(s + " : " + r.getString(s) + " | ");
  • Thx!, thought the reason that I was using a class was because I thought that at all times you have to revert to classes. But it seems that this is not always the case.. (?)

  • Actually, a Processing's sketch is itself a Java class! ;)

  • Well, it all works now as intended. Thank you very much ;)

Sign In or Register to comment.