Hi, Could anyone tell me why this following code gives me a NullPointerException?

1 2 3 4 5
| Vector2 e1 = vertices[i]; Vector2 e2 = vertices[i + 1 == vertices.length ? 0 : i + 1]; Vector2 edge = e1.subtract(e2); |

Vector2 Constructors and variables

1 2 3 4 5 6 7 8 9 10 11
| public float x, y; public Vector2(float x, float y){ this.x = x; this.y = y; } public Vector2(Vector2 vec){ this.x = vec.x; this.y = vec.y;
} |

Code to subtract vector

1 2 3 4 5
| public Vector2 subtract(Vector2 vec){
return new Vector2(x - vec.x, y - vec.y);
} |