Code listing in LaTeX beamer presentation frames - Stack Overflow

fragileオプションが必要.

\begin{frame}[fragile]
  \frametitle{Test}
 \begin{lstlisting}
    public class SimpleClass {
      public static void main(String[] args) {
        System.out.println("Hello!");
      }
    }
  \end{lstlisting}
\end{frame}