Homoclinic solutions for a class of nonperiodic and noneven second-order Hamiltonian systems