In my preamble I have the following custom environment that is counted.
\newtheorem{exmp}{Example}[section]
When I call this in the text I always write the following piece of code,
\begin{exmp}
\begin{mdframed}[backgroundcolor=blue!20]
Whatever I want to write ...
\end{mdframed}
\end{exmp}
I then wish to enter a figure within this environment.
\begin{exmp}
\begin{mdframed}[backgroundcolor=blue!20]
\begin{figure}[h!]
\centering
\includegraphics[width=8cm, height=5cm]{name-of-figure}
\caption{The caption. }
\label{fig:RC}
\end{figure}
\end{mdframed}
\end{exmp}
I then get the the following two errors:
Latex error: Not in outer par mode.
Missing number, treated as zero.
Everything compiles fine when the code for the figure is removed. Unfortunately the figure really does have to be within the environment. I have absolutely zero idea on how to go about fixing this and appreciate any help you can offer! As an aside I then wish to match the colour of the image to the colour of the mdframed environment, however I have not attempted this yet for obvious reasons!

figurewants to float, while themdframedis preventing it from doing that. – Werner Dec 15 '15 at 19:48\begin{figure}and to\begin{center}and likewise for the end of the environment. Load the caption package, and use\captionof{figure}{Whatever}. – Ian Thompson Dec 15 '15 at 19:51