# Importing libraries into classes

**URL:** <https://discourse.processing.org/t/importing-libraries-into-classes/11710>\
**Category:** Beginners\
**Created:** [May 30, 2019, 3:52pm UTC](https://discourse.processing.org/t/importing-libraries-into-classes/11710 "2019-05-30T15:52:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [May 30, 2019, 3:52pm UTC](https://discourse.processing.org/t/importing-libraries-into-classes/11710/1 "2019-05-30T15:52:43Z")

</div>

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 )

```auto
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!

---

<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:** [May 30, 2019, 4:12pm UTC](https://discourse.processing.org/t/importing-libraries-into-classes/11710/2 "2019-05-30T16:12:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [May 30, 2019, 4:25pm UTC](https://discourse.processing.org/t/importing-libraries-into-classes/11710/3 "2019-05-30T16:25:27Z")

</div>

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?

---

<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:** [May 30, 2019, 4:29pm UTC](https://discourse.processing.org/t/importing-libraries-into-classes/11710/4 "2019-05-30T16:29:28Z")

</div>

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

---

<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:** [May 30, 2019, 5:32pm UTC](https://discourse.processing.org/t/importing-libraries-into-classes/11710/5 "2019-05-30T17:32:47Z")

</div>

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

Try this

```auto
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

```auto
something = new Something(this);

```

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [May 30, 2019, 7:29pm UTC](https://discourse.processing.org/t/importing-libraries-into-classes/11710/6 "2019-05-30T19:29:43Z")

</div>

I figured it out yes thanks!
