# Library/Class Error

**URL:** <https://discourse.processing.org/t/library-class-error/4467>\
**Category:** Development\
**Created:** [October 14, 2018, 7:04pm UTC](https://discourse.processing.org/t/library-class-error/4467 "2018-10-14T19:04:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![JuniorGenius](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/juniorgenius/32/1163_2.png) [@JuniorGenius](https://discourse.processing.org/u/JuniorGenius)\
**Post date:** [October 14, 2018, 7:04pm UTC](https://discourse.processing.org/t/library-class-error/4467/1 "2018-10-14T19:04:08Z")

</div>

So I am creating a physics library, and I made a class for shapes. I included the class in the collisions file, tried creating a shape in the collisions class, and got the error “the class does not exist”. I tried moving the geometry class to the same tab as the collisions class, and it said the same thing. I’ve had this occur before, too. Any help, please? It is really frustrating me.

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [October 15, 2018, 12:34am UTC](https://discourse.processing.org/t/library-class-error/4467/2 "2018-10-15T00:34:50Z")

</div>

> [@JuniorGenius](#):
>
> I am creating a physics library

Are you creating the library for Processing in Java, or creating functions for Processing in Processing code?

If you move the shape class into the same tab and locate it before the geometry class, do you still get the same error?

If you want to use multiple tabs you can try to put `void setup() {}`in the last line of your main (first) tab.

If we could see your code or some code that shows your error, it would be extra helpful. 🙂

---

<div class="post-metadata">

**Author:** ![JuniorGenius](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/juniorgenius/32/1163_2.png) [@JuniorGenius](https://discourse.processing.org/u/JuniorGenius)\
**Post date:** [October 17, 2018, 1:24am UTC](https://discourse.processing.org/t/library-class-error/4467/3 "2018-10-17T01:24:33Z")

</div>

I am creating the Processing Library in Processing code, but I will send a screenshot of the error! (But it is not a picture of the Library)

 ![4%2010_11_2018%204_16_34%20PM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/771c730fd105683b24aac30967d8c09beb2a5b2b.png)

---

<div class="post-metadata">

**Author:** ![JuniorGenius](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/juniorgenius/32/1163_2.png) [@JuniorGenius](https://discourse.processing.org/u/JuniorGenius)\
**Post date:** [October 17, 2018, 9:15pm UTC](https://discourse.processing.org/t/library-class-error/4467/4 "2018-10-17T21:15:39Z")

</div>

I _MIGHT_ have found the problem, but it _Might_ be a bug in the code.  
I found that if you don’t use the objects you create in the **Setup** method, it gives that error.  
I **think**.

---

<div class="post-metadata">

**Author:** ![Eeyorelife](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@Eeyorelife](https://discourse.processing.org/u/Eeyorelife)\
**Post date:** [October 17, 2018, 10:58pm UTC](https://discourse.processing.org/t/library-class-error/4467/5 "2018-10-17T22:58:28Z")

</div>

Why not use box2D? 🤔

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [October 18, 2018, 2:02am UTC](https://discourse.processing.org/t/library-class-error/4467/6 "2018-10-18T02:02:26Z")

</div>

Try putting line 3 underneath `class item {}`. I think the error may be because without `void setup() {}` the compiler only goes through the program once line by line, and on line 3, `item` doesn’t exist.

---

<div class="post-metadata">

**Author:** ![JuniorGenius](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/juniorgenius/32/1163_2.png) [@JuniorGenius](https://discourse.processing.org/u/JuniorGenius)\
**Post date:** [October 20, 2018, 5:48pm UTC](https://discourse.processing.org/t/library-class-error/4467/7 "2018-10-20T17:48:03Z")

</div>

I want to Create My own library that I completely understand, and I don’t know a lot about box2d.  
I do have the Original Box2d files, though, but they are for C/C++.

---

<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:** [October 23, 2018, 4:49pm UTC](https://discourse.processing.org/t/library-class-error/4467/8 "2018-10-23T16:49:10Z")

</div>

> [@JuniorGenius](#):
>
> I am creating the Processing Library in Processing code

Just be aware that you can’t actually do this. You can prototype library components in Processing sketches,  
or you can develop a collection of classes in .java files, but if you want a full Processing Library that can be installed and then used with Contributions Manager, then you have to develop it in Java and compile to jar – probably using e.g. Eclipse or IntelliJ. See for example the  
Processing Library Template.

> **[GitHub - processing/processing-library-template: Processing Library Template...](https://github.com/processing/processing-library-template)**
>
> Processing Library Template for Eclipse. Contribute to processing/processing-library-template development by creating an account on GitHub.

**Edit**  
Note that if you want to use your own classes in a Processing sketch then **one option is to** add a `void setup(){}` or `void draw(){}`, even if it is empty. You don’t need to _use_ the objects in setup – you just need to have one of those functions existing. Otherwise the sketch is compiled in Immediate Mode and classes will **only work if defined before an instance is declared**.

Also: you can click on that little tiny copy-clipboard icon on the red warning bar to copy the error message to your clipboard. No screenshot needed.

---

<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:** [October 24, 2018, 6:37am UTC](https://discourse.processing.org/t/library-class-error/4467/9 "2018-10-24T06:37:26Z")

</div>

> [@jeremydouglass](#):
>
> Otherwise the sketch is compiled in Immediate Mode and classes will not work.

Actually classes do work under the Immediate Mode: 😮

```java
class Vec extends PVector {
  float x, y, z;
}

final Vec vec = new Vec();
println(vec);

exit();

```

---

<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:** [October 24, 2018, 3:11pm UTC](https://discourse.processing.org/t/library-class-error/4467/10 "2018-10-24T15:11:36Z")

</div>

Ah, interesting. I hadn’t realized that because I never use Immediate mode – it makes sense on reflection based on how Processing works.

1. In immediate mode, you must define the class before you use it, just like you must define x before using it.
2. in a setup() / draw() sketch, on the other hand, you may define the class anywhere, and traditionally the class code comes after declaration / setup / draw, and/or in a separate tab.

So this is valid:

```auto
myClass c;
void setup(){
}
class myClass {}

```

and this is valid:

```auto
class myClass {}
myClass c;

```

but this is not valid:

```auto
myClass c;
class myClass {}

```

---

<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:** [October 24, 2018, 3:33pm UTC](https://discourse.processing.org/t/library-class-error/4467/11 "2018-10-24T15:33:06Z")

</div>

> [@jeremydouglass](#):
>
> In immediate mode, you must define the class before you use it,

- In immediate mode, the whole sketch is wrapped up inside a PApplet method.
- W/ the exception of lambdas, Java doesn’t allow local methods inside another method.
- However, local classes are allowed! And we have to define them before accessing them.

---

<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:** [October 24, 2018, 3:40pm UTC](https://discourse.processing.org/t/library-class-error/4467/12 "2018-10-24T15:40:20Z")

</div>

> [@jeremydouglass](#):
>
> In a **setup()** / **draw()** sketch, on the other hand, you may define the class anywhere, …

- B/c all classes & interfaces inside “.pde” files are nested to a PApplet subclass.
- It’s not the same as a local-scoped class or interface under Immediate Mode.
