This phase II trial is studying erlotinib hydrochloride to see how well it works in treating patients with advanced esophageal cancer or stomach cancer. Erlotinib hydrochloride may stop the growth of cancer by blocking the enzymes necessary for tumor cell growth.