Why did God kill Er?


For being wicked in the sight of the Lord

And Er, Judah's firstborn, was wicked in the sight of the LORD; and the LORD slew him. Genesis 38:7