# \`The sketch path is not set.\` error when loading table in global

**URL:** <https://discourse.processing.org/t/the-sketch-path-is-not-set-error-when-loading-table-in-global/9952>\
**Category:** Beginners\
**Created:** [April 4, 2019, 6:27am UTC](https://discourse.processing.org/t/the-sketch-path-is-not-set-error-when-loading-table-in-global/9952 "2019-04-04T06:27:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmt2080ad](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jmt2080ad](https://discourse.processing.org/u/jmt2080ad)\
**Post date:** [April 4, 2019, 6:27am UTC](https://discourse.processing.org/t/the-sketch-path-is-not-set-error-when-loading-table-in-global/9952/1 "2019-04-04T06:27:49Z")

</div>

I have a large 500K row table that I am trying to use for animating a point. All the examples I can find for `loadTable()` show the table loading in `draw()` and using a for loop there to iterate over rows. What I want to do is load the table once, then call rows by index. This code, where I try to load the table in global scope, is giving me a `The sketch path is not set.` error. When I put the `loadTable()` call in `draw()` it works, but is slow, or at least seems slow.

Is there a reason why when `loadTable()` is called in the global scope I am getting this error?

```auto
int rowCnt = 0;

void setup()
{
  size(200, 200);
  smooth();
  frameRate(1000);
}

Table table = loadTable("data/bd.csv", "header");

void draw()
{
  background(255, 255, 255);
  TableRow row = table.getRow(rowCnt);
  int cnt = row.getInt("bike_count");
  ellipse(100, 20 + cnt, 10, 10);
  rowCnt += 1;
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 4, 2019, 6:31am UTC](https://discourse.processing.org/t/the-sketch-path-is-not-set-error-when-loading-table-in-global/9952/2 "2019-04-04T06:31:54Z")

</div>

Problem is this line:

`Table table = loadTable("data/bd.csv", "header");`

instead:

`Table table;` outside setup ()

AND

The loading inside setup() after size()

Chrisir

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 4, 2019, 9:29am UTC](https://discourse.processing.org/t/the-sketch-path-is-not-set-error-when-loading-table-in-global/9952/3 "2019-04-04T09:29:40Z")

</div>

also your program flow in the draw loop would show?  
one row per frame until error end of table

pls start from here:

```auto
// simple CSV read to spreadsheet
Table data;
String data_fn = "data/bd.csv";
int dc = 60, dx = 10, dr =20, posx, posy;

void setup() {
  size(500, 500);
  data = loadTable(data_fn, "header");
}

void draw() {
  background(80, 80, 0);
  for (int c =0; c < data.getColumnCount(); c++) text(data.getColumnTitle(c), dx+c*dc, dr); // data Column Header
  
  for (int r = 0; r < data.getRowCount(); r++) for (int c =0; c < data.getColumnCount(); c++) { // data
    posx = dx+c*dc;      
    posy = (r+1)*dr;
    text(data.getString(r, c), posx, dr + posy); // data cell content
  }
}

//data/bd.csv
/*
town,bike_count
here,234
there,567
nowhere,0
*/

```

 ![SNAG-0054](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b2358fd8a1ff98119656c61e767cdafd7d15e8ec.jpeg)

---

<div class="post-metadata">

**Author:** ![jmt2080ad](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jmt2080ad](https://discourse.processing.org/u/jmt2080ad)\
**Post date:** [April 5, 2019, 2:31am UTC](https://discourse.processing.org/t/the-sketch-path-is-not-set-error-when-loading-table-in-global/9952/4 "2019-04-05T02:31:12Z")

</div>

Great, thank you both. I was struggling with how scope the `Table` object. Here is the final working sketch:

```auto
Table data;
int rowCnt = 0;

void setup() {
  size(200, 200);
  frameRate(10);
  data = loadTable("data/bd.csv", "header");
}

void draw() {
  background(255, 255, 255);
  TableRow row = data.getRow(rowCnt);
  int cnt = row.getInt("bike_count");
  ellipse(100, 20 + cnt, 10, 10);
  rowCnt += 1;
}

```

A remaining question I have is, why can’t the `Table` object be assigned in the header, as `rowCnt` is?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 5, 2019, 8:30am UTC](https://discourse.processing.org/t/the-sketch-path-is-not-set-error-when-loading-table-in-global/9952/5 "2019-04-05T08:30:37Z")

</div>

> [@jmt2080ad](#):
>
> , why can’t the Table object be assigned in the header, as _rowCnt_ is?

B/c all Processing’s loading functions depend on PApplet::_sketchPath_ to be already initialized: 📂

> [@File Listing Order](https://discourse.processing.org/t/file-listing-order/7148/20):
>
> Your sketch is buggy! You’re calling dataFile() before settings()! bug The private system field PApplet::sketchPath is initialized just before settings() is called back btW. calling[Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#sketchPath--](http://Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#sketchPath--)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 5, 2019, 8:34am UTC](https://discourse.processing.org/t/the-sketch-path-is-not-set-error-when-loading-table-in-global/9952/6 "2019-04-05T08:34:47Z")

</div>

The loading must be after size() command to work
