Other characters and friends of Ted are Marshall Eriksen ( Jason Segel ) , Robin Scherbatsky ( Cobie Smulders ) , Barney Stinson ( Neil Patrick Harris ) , and Lily Aldrin ( Alyson Hannigan ) . How I Met Your Mothers other main characters are Lily Aldrin ( Alyson Hannigan ) , Marshall Eriksen ( Jason Segel ) , Robin Scherbatsky ( Cobie Smulders ) , and Barney Stinson ( Neil Patrick Harris ) .