[Tex/LaTex] Environment lstlisting undefined

environmentslistings

Hi I have installed the listings package in order to display my code. I am running the following code within my document:

\begin{lstlisting}
public static void main(String[] args) {
System.out.println("Hello World");
}
\end{lstlisting}

But that is giving me the following error:

! LaTeX Error: Environment lstlisting undefined.

I have mentioned \usepackage{listings} so I really dont know what the problem can be. Would anyone be kind enough to help or guide me the right way?

EDIT: Minimum working example:

\documentclass[a4paper,12pt]{book}

\usepackage{times,a4wide}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{listings}

\begin{document}

\begin{lstlisting}
public static void main(String[] args) {
System.out.println("Hello World");
}
\end{lstlisting}

\end{document}  

Best Answer

Based on the information you have given us, and due to the fact that your MWE runs OK in several of our systems (and even yours when pasted into a new document) I humbly conclude that there must be a typo somewhere in your original document.

As an immediate workaround, you could use the verbatim environment:

\begin{verbatim}
public static void main(String[] args) {
System.out.println("Hello World");
}
\end{verbatim}

But as mentioned before, this code runs perfectly on my system:

\documentclass{article}

\usepackage{listings}

\begin{document}

\begin{lstlisting}
public static void main(String[] args) {
System.out.println("Hello World");
}
\end{lstlisting}

\end{document}