In this paper, we further develop recent results in the numerical solution of Hamiltonian partial differential equations (PDEs) (Brugnano et al., 2015), by means of energy-conserving methods in the class of Line Integral Methods, in particular, the Runge–Kutta methods named Hamiltonian Boundary Value Methods (HBVMs). We shall use HBVMs for solving the nonlinear Schrödinger equation (NLSE), of interest in many applications. We show that the use of energy-conserving methods, able to conserve a discrete counterpart of the Hamiltonian functional, confers more robustness on the numerical solution of such a problem. [ABSTRACT FROM AUTHOR]