# Data visualization – sketch set-up error

**URL:** https://discourse.processing.org/t/data-visualization-sketch-set-up-error/11632
**Category:** Coding Questions
**Created:** [May 27, 2019, 12:10pm UTC](https://discourse.processing.org/t/data-visualization-sketch-set-up-error/11632 "2019-05-27T12:10:12Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Darius](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@Darius](https://discourse.processing.org/u/Darius)
#### Post date: [May 27, 2019, 12:10pm UTC](https://discourse.processing.org/t/data-visualization-sketch-set-up-error/11632/1 "2019-05-27T12:10:12Z")

</div>

Hi there, I am building a very simple sketch to visualize text and data.

It works when is like this(see below), but not when I use void setup and void draw (see second option after). does anyone know why? Thanks!

```auto
String filename= "test1.csv";
String [] sentence;
PFont f = createFont("Helvetica", 40);
 size(500,500);
 sentence=loadStrings(filename);
 printArray(sentence);
  textFont(f);
  textSize(40);
  text(sentence[1], 10, 100);

```

* * *

```auto
String filename= "test1.csv";
String [] sentence;
PFont f = createFont("Helvetica", 40);

void setup() {
 size(500,500);
 sentence=loadStrings(filename);
 printArray(sentence);
}

void draw(){
  textFont(f);
  textSize(40);
  text(sentence[1], 10, 100);
}

```

---

<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: [May 27, 2019, 12:13pm UTC](https://discourse.processing.org/t/data-visualization-sketch-set-up-error/11632/2 "2019-05-27T12:13:30Z")

</div>

What happens falsely, does it start, does it throw an error?

Maybe move this

```auto
f = createFont(“Helvetica”, 40);

```

Into setup after size

---

<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: [May 27, 2019, 12:23pm UTC](https://discourse.processing.org/t/data-visualization-sketch-set-up-error/11632/3 "2019-05-27T12:23:26Z")

</div>

as you use a .csv file i assume you would be better of using  
[https://processing.org/reference/loadTable\_.html](https://processing.org/reference/loadTable_.html)  
instead of  
[https://processing.org/reference/loadStrings\_.html](https://processing.org/reference/loadStrings_.html)

* * *

anyhow

```auto
String filename= "test1.csv";
String [] sentence;
sentence=loadStrings(filename);
printArray(sentence);

```

works with the data file in  
/data/test1.csv

same as

```auto
String filename= "test1.csv";
String [] sentence;

void setup() {
size(500,500);
sentence=loadStrings(filename);
printArray(sentence);
}

void draw(){}

```

---

<div class="post-metadata">

### Author: ![Darius](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@Darius](https://discourse.processing.org/u/Darius)
#### Post date: [May 27, 2019, 12:24pm UTC](https://discourse.processing.org/t/data-visualization-sketch-set-up-error/11632/4 "2019-05-27T12:24:34Z")

</div>

Yes, the error it gives is:  
java.lang.reflect.InvocationTargetException

---

<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: [May 27, 2019, 12:27pm UTC](https://discourse.processing.org/t/data-visualization-sketch-set-up-error/11632/5 "2019-05-27T12:27:48Z")

</div>

> [@Darius](#):
>
> createFont

So no createFont before setup, instead after size

Before setup

PFont f ;

In setup() (after size() command)

f = createFont(“Helvetica”, 40);

---

<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: [May 27, 2019, 12:28pm UTC](https://discourse.processing.org/t/data-visualization-sketch-set-up-error/11632/6 "2019-05-27T12:28:58Z")

</div>

Yes, is the csv file located in your data folder?

---

<div class="post-metadata">

### Author: ![Darius](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@Darius](https://discourse.processing.org/u/Darius)
#### Post date: [May 27, 2019, 12:29pm UTC](https://discourse.processing.org/t/data-visualization-sketch-set-up-error/11632/7 "2019-05-27T12:29:04Z")

</div>

Great! That works! Thanks:)

---

<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: [May 27, 2019, 12:30pm UTC](https://discourse.processing.org/t/data-visualization-sketch-set-up-error/11632/8 "2019-05-27T12:30:44Z")

</div>

I think a few things are set up in the size() command behind the scenes.

Hence some commands only work after size(), especially file related stuff and width and height…

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [May 31, 2019, 4:39pm UTC](https://discourse.processing.org/t/data-visualization-sketch-set-up-error/11632/9 "2019-05-31T16:39:11Z")

</div>

Yes, while it isn’t strictly enforced, the Processing documentation actually says **must** :

> In a program that has the **setup()** function, the **size()** function **MUST** be the first line of code inside **setup()** , and the **setup()** function must appear in the code tab with the same name as your sketch folder. [size() / Reference / Processing.org](https://processing.org/reference/size_.html)

---

<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: [May 31, 2019, 7:47pm UTC](https://discourse.processing.org/t/data-visualization-sketch-set-up-error/11632/10 "2019-05-31T19:47:18Z")

</div>

> [@jeremydouglass](#):
>
> , the Processing documentation actually says **must** :

I know Processing since v1.5.1. Even back then, that wasn’t a MUST. 😆
