I am using IntelliJ idea
, processing
, peasy
and obviously Java
to run everything. I'm trying to use PeasyCam in my setting()
method and it keeps giving me this error:
java.lang.NullPointerException: Cannot read field "width" because "<parameter2>" is null
at peasy.PeasyCam.<init>(Unknown Source)
at peasy.PeasyCam.<init>(Unknown Source)
at com.nod.planets.Main.settings(Main.java:14)
at processing.core.PApplet.handleSettings(PApplet.java:978)
at processing.core.PApplet.runSketch(PApplet.java:10897)
at processing.core.PApplet.main(PApplet.java:10657)
at processing.core.PApplet.main(PApplet.java:10639)
at com.nod.planets.Main.main(Main.java:45)
Honestly I'm completely new to peasy and processing and I'm stuck when it comes to debugging this.
Here's the code for reference:
package com.nod.planets;
import processing.core.PApplet;
import peasy.*;
public class Main extends PApplet
{
PeasyCam cam;
@Override
public void settings()
{
size(600, 600, P3D);
cam = new PeasyCam(this, 200);
}
@Override
public void draw()
{
background(0);
fill(255);
lights();
//translate(width / 2, height / 2);
float sphereRadius = 200;
int sphereVertices = 100;
for (int i = 0; i < sphereVertices; i++)
{
float longitude = map(i, 0, sphereVertices, -PI, PI);
for (int j = 0; j < sphereVertices; j++)
{
float latitude = map(j, 0, sphereVertices, -HALF_PI, HALF_PI);
float x = sphereRadius * sin(longitude) * cos(latitude);
float y = sphereRadius * sin(longitude) * sin(latitude);
float z = sphereRadius * cos(longitude);
stroke(255);
strokeWeight(2);
point(x, y, z);
}
}
}
public static void main(String[] args)
{
PApplet.main("com.nod.planets.Main");
}
}
If I get rid of initializing the PeasyCam and uncomment the translate(width / 2, height / 2);
code then it works like a charm, but the minute I try this it gives that error... It's just this damn "easy" "PeasyCam" that's giving me the trouble. Also yes I am trying to make planets with perlin noise terrain in case you're wondering. Don't @ me on whether it'll work or not (idk tbh), just please help me in figuring out why it's giving me this error.
question from:
https://stackoverflow.com/questions/65854399/java-lang-nullpointerexception-while-using-peasycam-and-processing-peasycam-say 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…