Reference to a listing returns wrong number

I think the lstlisting environment prefers the label to be inserted as a normal parameter:

Adapt the following code to your needs and see if you obtain what you want:

\documentclass{article}
\usepackage{listings}

\begin{document}
\begin{lstlisting}[caption={Some Java code},label={lst:label},language=Java]
// Code...
\end{lstlisting}
See code~\ref{lst:label}.
\end{document} 

The problem is that in the lstlisting declaration you should use label={example} instead of \label{example}.

\begin{lstlisting}[language={[Sharp]C}, caption={example is here}, label={example}]