Importing libraries into classes

Hey there!

I have been running into an issue where I would like to import a library into a file but when I do make the file and my own class it doesn’t recognize that the library is imported and doesn’t let me use what I have imported.
So for example trying to import the .net library and having this in my own class ( Import is above class )

import processing.net.*;
public class Something{
  Client c;
  Something(){
     c = new Client(this,"192.",124);
  }
}

Processing will just prompt : The constructor “Client(ServerClient, String, int)” does not exist

I am assuming it is an issue with the this as in the error it prompts the name of the class but I am not sure to what swap the this for. Also the object is allowed to be initialized just can’t make the constructor. Because of the above problem !

Any solutions to the issue ? Thanks in advance!

1 Like

General rule: initialize assets in setup(), where the keyword this is of datatype PApplet.

But I would like to initialize outside of setup() in a class which hold just that object rather than where setup() is. Can it be done?

For that, your class’ gonna need to request the sketch’s PApplet reference.

1 Like

In your code this is of type Something when the constructor is expecting a PApplet

Try this

import processing.net.*;

public class Something{
  Client c;
  Something(PApplet app){
     c = new Client(app,"192.",124);
  }
}

When you create Something from the make sketch code use

something = new Something(this);
2 Likes

I figured it out yes thanks!