Some of these may help (probably you don't need all these lines):
\usepackage[german]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\lstset{literate=% Allow for German characters in lstlistings.
{Ö}{{\"O}}1
{Ä}{{\"A}}1
{Ü}{{\"U}}1
{ß}{{\ss}}2
{ü}{{\"u}}1
{ä}{{\"a}}1
{ö}{{\"o}}1
}
Here you'll find similar code for lots of other languages and characters, and some other hints to this same problem:
https://stackoverflow.com/questions/1116266/listings-in-latex-with-utf-8-or-at-least-german-umlauts/15450398
P.S. Whenever you use lstlisting, you usually want to add something like this for other reasons (they don't affect your problem):
\usepackage{listings}
\lstset{
basicstyle=\small\ttfamily, %Looks much better.
columns=flexible, %Without this you get fixed-width fonts, which look bad.
breaklines=true, %End-of-line wrap - you really want this, usually.
language=tex %Percent comments in cursive, so you distinguish them from the commands. Other languages are also available, such as C and Matlab.
}
\lstinputlisting
:that you've used an editor that's been too clever, and the file that you thought wasn't utf8 now is, with some odd unicode characters hidden by the editor at the start. I was getting the same error message as this on the first line, whatever I put at the start of the file. The � may be a real unicode character U+FFFD:REPLACEMENT CHARACTER in the output.