[Tex/LaTex] Verbatim in beamer showing error: “File ended while scanning use of \@xverbatim.”

beamerverbatim

I am using Texmaker and MiKTeX on Windows 7. I have the following beamer code,

\documentclass{beamer}
\theme{AnnArbor}
\begin{document}
\begin{frame}
\begin{verbatim}

   \begin{frame}[<alignment>]
   \frametitle{Frame Title Goes Here}
   Frame body text and/or LATEX code
   \end{frame}

\end{verbatim}
\end{frame}
\end{document}

I was expecting the following output,

       \begin{frame}[<alignment>]
       \frametitle{Frame Title Goes Here}
       Frame body text and/or LATEX code
       \end{frame}

But instead I got the following Error Message,

File ended while scanning use of \@xverbatim.

Can any one please point out the error here. As far as I know verbatim can have anything inside it.

Also when I tried the following code,

\begin{verbatim}
 \ begin{frame}[<alignment>]
 \frametitle{Frame Title Goes Here}
 Frame body text and/or LATEX code
 \ end{frame}
\end{verbatim}

I got the following output,

    \ begin{frame}[<alignment>]
     \frametitle{Frame Title Goes Here}
     Frame body text and/or LATEX code
    \ end{frame}

But I don't want space between \ and begin and \ and end.

Best Answer

Your frame should be fragile. (One additional line commented for better effect).

\documentclass{beamer}
%\theme{AnnArbor}

\begin{document}
%\begin{frame}
\begin{frame}[fragile]
\begin{verbatim}

   \begin{frame}[<alignment>]
   \frametitle{Frame Title Goes Here}
   Frame body text and/or LATEX code
   \end{frame}

\end{verbatim}
\end{frame}
\end{document}

enter image description here