Library/Class Error

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.

1 Like

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. :slight_smile:

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)

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.

Why not use box2D? :thinking:

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.

1 Like

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++.

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.

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.

Actually classes do work under the Immediate Mode: :open_mouth:

class Vec extends PVector {
  float x, y, z;

final Vec vec = new Vec();


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:

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

and this is valid:

class myClass {}
myClass c;

but this is not valid:

myClass c;
class myClass {}
  • 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.
1 Like
  • 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.
1 Like