[Tex/LaTex] Missing number treated as zero and Illegal unit of measure when using subfigure

subfloats

I am trying to put two figures side by side and keep getting these two errors:

Missing number treated as zero.
Illegal unit of measure.

The only way I don't get them is if I comment the {0.5\textwidth}. However if I comment it the figures stay one under the other.

\begin{figure}
    \begin{subfigure}{0.5\textwidth}
        \centering
        \includegraphics[width=0.4\linewidth]{Figuras/SICAPI2014.eps}
        \caption{SICAPI}
        \label{fig.SICAPI}
    \end{subfigure}%

\begin{subfigure}{0.5\textwidth}
    \centering
    \includegraphics[width=0.4\linewidth]{Figuras/painel_sicapi.eps}
    \caption{Painel de operação}
    \label{fig.painel_sicapi}
\end{subfigure}

\caption{Planta Piloto SICAPI}
\label{fig.sicapi}
\end{figure}

Best Answer

As @Bernard say in his comment, blank lines between sub figures tell to LaTeX: "Put them each in own line". In similar cases I wrote as follows:

\documentclass{article}
    \usepackage{graphicx}

    \usepackage{caption}
    \usepackage{subcaption}

    \begin{document}
\begin{figure}[!ht]
    \centering% center subfigures in float
    \begin{subfigure}{0.45\textwidth}
        \includegraphics[width=\hsize]{example-image}
        \caption{SICAPI}
        \label{fig.SICAPI}
    \end{subfigure}
\hfil% accomodate space between sub figures
    \begin{subfigure}{0.45\textwidth}
    \includegraphics[width=\hsize]{example-image}
    \caption{Painel de operação}
    \label{fig.painel_sicapi}
\end{subfigure}
    \caption{Planta Piloto SICAPI}
    \label{fig.sicapi}
\end{figure}
    \end{document}

I didn't check where arise errors about which you complain. In above example they are not presented. How to use subfigure se package documentation or brief description in Wikibooks: LaTeX/Floats, Figures and Captions.