2

So I have .pde file and several .java files that are used in a project. I import the library as so into a .java file:

import processing.serial.*;

When I import the Processing serial library in the .pde file it works fine, but when I import the Processing serial library into a .java file I get this error:

The package "processing.serial" does not exist. You might be missing a library

Libraries must be installed in a folder named 'libraries' inside the sketchbook folder (see the Preferences window).

Do I need to install the library to be able to use it with a .java file or is there another solution to import the Processing serial library into a .java file?

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
karamazovbros
  • 950
  • 1
  • 11
  • 40

1 Answers1

1

Libraries don't come automatically included with Processing. You have to add them to your sketch using the Sketch > Import Library menu. This is true whether you're in the main sketch file or in a .java tab.

Shameless self-promotion: here is a tutorial on using libraries in Processing.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
  • Yes, but you'll notice when going through Sketch > Import Library, Serial is already there and if you look up Serial in the "Add Library.." window you won't find the correct library. The serial library is located in the processing folder when downloaded in the modes\java\libraries\serial folder, so it does not need to be downloaded. It does need the import lines in both .pde and .java though. – karamazovbros Jul 16 '18 at 22:36
  • @karamazovbros Yes, it's downloaded, but it's not added to the sketch until you go to `Sketch > Import library` and choose the Serial library. This does two things: it adds the library to your classpath, and it adds some import statements at the top. Just adding the import statements isn't enough, you have to add the library first! – Kevin Workman Jul 16 '18 at 22:39
  • 1
    Oh okay, I didn't know about the adding the library to the classpath part, I just thought it added the import statements. – karamazovbros Jul 16 '18 at 22:43