1

I'm trying to import the GSON library into my processing java sketch. The editor I'm using is VS Code. I'm fairly new to how libraries work in Java, so I followed what many sites said. Here's what I did.

  1. First, I downloaded the GSON .jar file from this site.
  2. Next, In my processing sketch within VS Code, I created folders called libraries and library, so that the file structure looked like this: /sketch/libraries/library.
  3. Then, I renamed the downloaded file from step 1 to gson.jar and put it in both the libraries then library folder.
  4. Finally, I imported the libraries at the top of my sketch like so:
import com.google.gson.Gson; 
import com.google.gson.GsonBuilder;

However, I still get the library not found error:

No library found for com.google.gson No library found for com.google.gson Libraries must be installed in a folder named 'libraries' inside the sketchbook folder (see the Preferences window). main.pde:0:0:0:0: The package “com.google” does not exist. You might be missing a library.

What am I doing wrong? Am I missing a step?

Thanks for any help.

Scollier
  • 575
  • 6
  • 19

1 Answers1

0

A simpler option would be to drop gson-2.8.2.jar into a Processing sketch. This will create a code folder with the jar inside the import should work from there:

import com.google.gson.Gson; 
import com.google.gson.GsonBuilder;

println(Gson.class);// prints class com.google.gson.Gson

The downside is the jar is visible per sketch.

If you want the library to be visible to all sketches as if it's a Processing library, as you've attempt, the folder structure is slightly different:

/path/to/Processing/libraries/YourLibrary/library/YourLibrary.jar

e.g. Documents/Processing/libraries/Gson/library/Gson.jar

(indeed you need to rename gson-2.8.2.jar to match the grandparent folder name)

Additionally, if you don't mind a simpler JSON parser, just uses the built-in loadJSONObject() / loadJSONArray() functions

George Profenza
  • 50,687
  • 19
  • 144
  • 218