drc
1
Hi,
I’d like to use the FastNoise library. I drag&dropped the FastNoise.java to a new sketch, and with the following code:
FastNoise myNoise;
void setup() {
myNoise.SetNoiseType(FastNoise.NoiseType.SimplexFractal);
}
I get the NullPointerException error, highlighting the only line in setup.
Could you please help me here? How should I use this library?
thanks!
- You had merely declared field myNoise w/o initializing it:
FastNoise myNoise;
- A reference field always defaults to
null
under Java.
- We can’t do anything to a
null
value but checking out whether a variable has it stored.
Ru sure it’s SetNoiseType()? Under Java’s naming conventions that should be named: setNoiseType().
hamoid
3
Here’s the link to the library:
Apparently it is SetNoiseType
and not setNoiseType
. For some reason all the methods are upper case.
In Ubuntu I had to download one dependency to make it work:
$ sudo apt install libvecmath-java
$ dpkg -L libvecmath-java | grep jar$
/usr/share/java/vecmath-1.5.2.jar
/usr/share/java/vecmath.jar
$ cd into/my/sketch/folder
$ mkdir code
$ cp /usr/share/java/vecmath.jar code/
Then I could run
FastNoise myNoise;
void setup() {
myNoise = new FastNoise();
myNoise.SetNoiseType(FastNoise.NoiseType.SimplexFractal);
println(myNoise.GetNoise(0.1, 0.2, 0.3));
}
The examples in GitHub look interesting. For example:
1 Like
hamoid
4
By the way, this change removes the dependency on javax.vecmath, making it self contained.
drc
5
Thank you both! Now it works fine (I’ve already downloaded the vecmath before).