Null Pointer when subtracting a Vector

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

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

Vector2 Constructors and variables

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

public Vector2 subtract(Vector2 vec){
//NullPointerException at this point
      return new Vector2(x - vec.x, y - vec.y);

   }