# How to get the sketchPath from a static method

**URL:** <https://discourse.processing.org/t/how-to-get-the-sketchpath-from-a-static-method/1617>\
**Category:** Coding Questions\
**Created:** [July 9, 2018, 10:05am UTC](https://discourse.processing.org/t/how-to-get-the-sketchpath-from-a-static-method/1617 "2018-07-09T10:05:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manuel](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Manuel](https://discourse.processing.org/u/Manuel)\
**Post date:** [July 9, 2018, 10:05am UTC](https://discourse.processing.org/t/how-to-get-the-sketchpath-from-a-static-method/1617/1 "2018-07-09T10:05:19Z")

</div>

Hi, I’ve tried everything I could think of to try to load a file inside an enum, but can’t get a way to reference to the current sketchPath statically. Does anyone know any posible solution?

That’s a small part of the code, but hopefully it’d be enough for you to understand the problem.

```auto
import java.io.File;
public enum SoundEffect {
   BELL("bell.wav"),
   BLOWER("blower.wav");

   // Each sound effect has its own clip, loaded with its own sound file.
   private Clip clip;

   // Constructor to construct each element of the enum with its own sound file.
   SoundEffect(String soundFileName) {
      try {
         // Use URL (instead of File) to read from disk and JAR.
         File soundFile = new File(soundFileName);

```

Thank you!

---

<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:** [July 9, 2018, 12:31pm UTC](https://discourse.processing.org/t/how-to-get-the-sketchpath-from-a-static-method/1617/2 "2018-07-09T12:31:13Z")

</div>

Static code can only access static members. 🤐  
Or else, request a non-static reference via a method/constructor’s parameter. 😳

---

<div class="post-metadata">

**Author:** ![Manuel](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Manuel](https://discourse.processing.org/u/Manuel)\
**Post date:** [July 9, 2018, 12:53pm UTC](https://discourse.processing.org/t/how-to-get-the-sketchpath-from-a-static-method/1617/3 "2018-07-09T12:53:20Z")

</div>

tbh I don’t know why sketchPath() isn’t a static method, but in the meantime I’m using the constructor method, but it’s a huge overhead as I had to make a container class for the enum, as I couldn’t get it to work with the enum itself :S

---

<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:** [July 9, 2018, 1:07pm UTC](https://discourse.processing.org/t/how-to-get-the-sketchpath-from-a-static-method/1617/4 "2018-07-09T13:07:07Z")

</div>

> [@Manuel](#):
>
> I don’t know why **sketchPath()** isn’t a `static` method,

B/c each instance of PApplet can have its own _sketchPath_ folder.

If the field _sketchPath_ were `static`, each instance of PApplet would be obliged to share the same folder path in order to save & load files.

---

<div class="post-metadata">

**Author:** ![Manuel](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Manuel](https://discourse.processing.org/u/Manuel)\
**Post date:** [July 10, 2018, 12:32pm UTC](https://discourse.processing.org/t/how-to-get-the-sketchpath-from-a-static-method/1617/5 "2018-07-10T12:32:59Z")

</div>

Seems fair enough, but why would you want to have multiple PApplet instances on the same instance of java?

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 10, 2018, 3:24pm UTC](https://discourse.processing.org/t/how-to-get-the-sketchpath-from-a-static-method/1617/6 "2018-07-10T15:24:30Z")

</div>

If you use multiple windows, you will have multiple applet instances. They have their own path assigned internally. Notice this path location can be “overriden” meaning you can ensure all instantiated applets points to the same sketch by providing extra arguments during their construction. This should be done if they want to get the access the same pool of user resources aka. images, fonts, etc. Why is this design like this? No clue. However, it is not that bad. At least, you can change the default path definition, if needed.

Kf

---

<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:** [July 10, 2018, 3:32pm UTC](https://discourse.processing.org/t/how-to-get-the-sketchpath-from-a-static-method/1617/7 "2018-07-10T15:32:13Z")

</div>

> [@kfrajer](#):
>
> At least, you can change the default path definition, if needed.

However in P3, the devs decided to slap a `private` access keyword to the field _sketchPath_. 🤬

Once _sketchPath_ is set, we can’t change it. Unless we use reflection on it. 😠

---

<div class="post-metadata">

**Author:** ![dan850](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dan850](https://discourse.processing.org/u/dan850)\
**Post date:** [July 10, 2018, 5:59pm UTC](https://discourse.processing.org/t/how-to-get-the-sketchpath-from-a-static-method/1617/8 "2018-07-10T17:59:52Z")

</div>

@GoToLoop I’m sure the Developers have been working really hard to make the source code as flexible as possible

---

<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:** [July 10, 2018, 6:21pm UTC](https://discourse.processing.org/t/how-to-get-the-sketchpath-from-a-static-method/1617/9 "2018-07-10T18:21:30Z")

</div>

I’m a forum goer since Processing 1.5.1.  
What I see is that devs’ decisions don’t take the forum into account at all! 😞

---

<div class="post-metadata">

**Author:** ![Manuel](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Manuel](https://discourse.processing.org/u/Manuel)\
**Post date:** [July 11, 2018, 12:44pm UTC](https://discourse.processing.org/t/how-to-get-the-sketchpath-from-a-static-method/1617/10 "2018-07-11T12:44:42Z")

</div>

I still wonder, under what circumpstances would you have multiple window applets assigned to different sketches but running under the same instance of java :S

---

<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:** [July 11, 2018, 12:57pm UTC](https://discourse.processing.org/t/how-to-get-the-sketchpath-from-a-static-method/1617/11 "2018-07-11T12:57:55Z")

</div>

It’s a matter of flexibility. They could easily declare field _sketchPath_ as `static`. 😛  
In such case, the last created [p]PApplet[/u] would determine the _sketchPath_ for all PApplet instances. 🤪
