java.lang.NullPointerException: Attempt to read from field ‘float processing.test.planets2.Planets2$planet.x’ on a null object reference
at processing.test.planets2.Planets2$planet.(Planets2.java:37)
at processing.test.planets2.Planets2.setup(Planets2.java:23)
at processing.core.PApplet.handleDraw(PApplet.java:1801)
at processing.core.PSurfaceNone.callDraw(PSurfaceNone.java:471)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:503)
java.lang.NullPointerException: Attempt to read from field ‘float processing.test.planets2.Planets2$planet.x’ on a null object reference
at processing.test.planets2.Planets2$planet.(Planets2.java:37)
at processing.test.planets2.Planets2.setup(Planets2.java:23)
at processing.core.PApplet.handleDraw(PApplet.java:1801)
at processing.core.PSurfaceNone.callDraw(PSurfaceNone.java:471)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:503)
planet other; //this is null
color average; //null (or maybe just 0)
float diameter; //0
float distance; //0
float speed; //0
float x=other.x+cos(speed)*distance; //this is doing this :
//float x = null.x (which is nothing, not 0, nothing...) +... and the rest.
//you are trying to access the x of a planet that you never defined
//defining means other = new Planet(...); or other = jupiter; but you didn’t do this yet
//and your first constructor never actually does that , only the second one.
float y=other.y+sin(speed)*distance;
Also, @Waboqueox , i‘m not sure if the OP want the x and y to be updated, but maybe to only be relative to the other Planets first x and y when created.