[Tex/LaTex] Error: \caption outside float

captionsfloats

When I add the following table (table1 shown below) I don't get any error, but when adding table2 (shown below) I get the error i)\caption outside float. \caption ii) Undefined control sequence \caption. What is the difference between these two table definitions? These two seems same to me.

latex code for table1 :

\begin{table}[h]
\begin{center}
\begin{tabular}{| p{2.5cm}| p{2.5cm} | p{2.5cm} |}
\hline
\textbf{AAA} & \textbf{BBB} & \textbf{CCC} \\
\hline
DDD   & 111 & 333\\ \hline
EEE   & 222 & 444\\ \hline
\end{tabular}
\end{center}

\caption{Caption1}
\label{table1}

\end{table}

……………………………………………………….

latex code for table2:

begin{table}[h]
\begin{center}
\begin{tabular}{| p{2.5cm}| p{2.5cm} |}
\hline
\textbf{GGG} & \textbf{HHH} \\
\hline
III                    &              113\\ \hline
JJJ                    &              234\\ \hline
KKK                    &              345\\ \hline
\end{tabular}
\end{center}
\caption{Caption2}
\label{table2}
\end{table}

Best Answer

The second table started with

begin{table}[h]

instead of

\begin{table}[h]

meaning it missed a \ and that was what gave the error of a caption outside a float.