# Creating a font in setup but getting error in draw that no font are loaded

**URL:** <https://discourse.processing.org/t/creating-a-font-in-setup-but-getting-error-in-draw-that-no-font-are-loaded/20195>\
**Category:** Coding Questions\
**Created:** [April 27, 2020, 7:18am UTC](https://discourse.processing.org/t/creating-a-font-in-setup-but-getting-error-in-draw-that-no-font-are-loaded/20195 "2020-04-27T07:18:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayfri](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ayfri/32/8797_2.png) [@Ayfri](https://discourse.processing.org/u/Ayfri)\
**Post date:** [April 27, 2020, 7:18am UTC](https://discourse.processing.org/t/creating-a-font-in-setup-but-getting-error-in-draw-that-no-font-are-loaded/20195/1 "2020-04-27T07:18:18Z")

</div>

Hi !  
I’m using this code to generate a font that and use it in my `setup` function :

```auto
public void setup() {
    PFont font = createFont("Arial", 32);
    textFont(font);
}

```

And on my `draw` function I just do

```auto
public void draw() {
    text("test ?", 10, 10);
};

```

but I’m getting this error :

```auto
java.lang.RuntimeException: Use textFont() before text()

```

I have a lot of code in these functions but nothing is using `text()` before the `setup` function, the only text that I’m trying to draw is in my `draw` function so it can’t be the cause right ?

So what am I doing wrong ?

---

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [April 27, 2020, 7:37am UTC](https://discourse.processing.org/t/creating-a-font-in-setup-but-getting-error-in-draw-that-no-font-are-loaded/20195/2 "2020-04-27T07:37:15Z")

</div>

Hi,

I run the following sketch and it worked for me. Please re-check your code or post its full version for someone trying to help you

```auto
public void setup() {
  size(120,120);
    PFont font = createFont("Arial", 32);
    textFont(font);
}

public void draw() {
  background(0);
    text("test ?", 20, 60);
}

```

Best regards

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [April 27, 2020, 8:28am UTC](https://discourse.processing.org/t/creating-a-font-in-setup-but-getting-error-in-draw-that-no-font-are-loaded/20195/3 "2020-04-27T08:28:00Z")

</div>

There are several reasons why this might happen, but it would help if you copy the full error message (might be several lines of text) shown in the console pane here.

---

<div class="post-metadata">

**Author:** ![Ayfri](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ayfri/32/8797_2.png) [@Ayfri](https://discourse.processing.org/u/Ayfri)\
**Post date:** [April 27, 2020, 8:32am UTC](https://discourse.processing.org/t/creating-a-font-in-setup-but-getting-error-in-draw-that-no-font-are-loaded/20195/4 "2020-04-27T08:32:41Z")

</div>

I found the reason, it was pretty stupid, the text that I tried to draw was in a PGraphics, and I found that we have to create the found into the PGraphics and not the main sketch 🐙

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [April 27, 2020, 8:42am UTC](https://discourse.processing.org/t/creating-a-font-in-setup-but-getting-error-in-draw-that-no-font-are-loaded/20195/5 "2020-04-27T08:42:39Z")

</div>

I have just been looking at the source code and this exception is thrown when PGraphics (or child class) does not have a parent PApplet. This agrees with what you found.
