How to load a csv file into a table?

I'm a relatively inexperienced programmer who's currently trying to load a .csv file into a table. However, I'm unable to figure out how to do so properly. I do have a data folder in the same directory as my .pde (it's the file that's generated when you save in processing right?) I'm also constantly getting static errors such as "cannot make a static reference to the non-static field files". I've looked over the OOP tutorial, but I'm still not understanding why I'm getting these errors.

public Table ultimate;
public String files[]; 

public static void main(String[] args)
{
  files = loadStrings("cereal.csv");
  ultimate = setup(files);
}
Table setup(String filename)
{
  Table table;
  table = loadTable(filename);
  println(table.getRowCount() + " total rows in table"); 

  for (TableRow row : table.rows()) {
    
    String cereal = row.getString("Cereal");
    String manufacturer = row.getString("Manufacturer");
    String type = row.getString("Type");
    int calories = row.getInt("Calories");
    int protein = row.getInt("Protein");
    int fat = row.getInt("Fat");
    int sodium = row.getInt("Sodium");
    float fiber = row.getFloat("Fiber");
    float carbohydrates = row.getFloat("Carbohydrates");
    int sugars = row.getInt("Sugars");
    int shelf = row.getInt("Shelf");
    int potassium = row.getInt("Potassium");
    int vitamins = row.getInt("Vitamins");
    float weight = row.getFloat("Weight");
    float cups = row.getFloat("Cups"); 
  }
  
  return table;
  
}

Answers

Sign In or Register to comment.