Problem with using \only command in beamer

I have created the following frame in beamer:

\begin{frame}[t]{Adjacency Matrix}
\vspace{1em}
\only<1>{
\vspace{0.5em}
An adjacency matrix is a square matrix used to represent a finite graph.
\end{block}
\vspace{0.5em}
For a graph with $\mathbold{\abs{V}}$ vertices, an adjacency matrix is a $\mathbold{\abs{V} \times \abs{V}}$ matrix.
\\\vspace{1em}
If the edge between vertex $\mathbold{i}$ and vertex $\mathbold{j}$ is denoted by $\mathbold{V_{i,j}}$ then there are two possibilities.
}

% ........

\end{frame}


Now inside this frame, I want several slides. For that I wrote the following code:

\setbeamertemplate{itemize items}[ball]
\begin{enumerate}
\only<2>{
\item Unweighted Graph
\vspace{1em}
\begin{itemize}
\item Matrix of 0s and 1s where in row $\mathbold{i}$ and column $\mathbold{j}$ is $1$ iff the edge $\mathbold{(i,j)}$ is in the graph
\end{itemize}

$\Scale[1]{ V_{i,j} = \begin{cases} 1 & if ~ edge(i,j) ~ exists \\ 0 & otherwise \end{cases} }$
}
\only<3>{
\item Weighted Graph
\begin{itemize}
\item Edge weight is placed in $\mathbold{V_{i,j}}$ entry if there is an edge and a special value (perhaps \textit{null} to indicate absence of an edge.
\end{itemize}
}
\end{enumerate}


I want the first item (Unweighted graph,enumerated 1) to show on slide 2 and the second item (Weighted graph,enumerated 2) to show on slide 3. But when I run this, on sharelatex, it shows the following error:

 main.tex, line 106
LaTeX Error: Something's wrong--perhaps a missing \item.

There are no entries found in a list you have created. Make sure you label list entries using the \item command, and that you have not used a list inside a table.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.106 \end{frame}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.


Currently, it's looking like this:

Both unweighted and weighted graph are enumerated 1.

What am I doing wrong?

The full code:

\documentclass[12pt]{beamer}
\usetheme{metropolis}
\usecolortheme{spruce}

\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{fixmath}
\usepackage{graphicx}

\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%
\newcommand*{\Resize}[2]{\resizebox{#1}{!}{$#2$}}%

\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\DeclarePairedDelimiter\norm{\lVert}{\rVert}%

% Swap the definition of \abs* and \norm*, so that \abs
% and \norm resizes the size of the brackets, and the
% starred version does not.
\makeatletter
\let\oldabs\abs
\def\abs{\@ifstar{\oldabs}{\oldabs*}}
%
\let\oldnorm\norm
\def\norm{\@ifstar{\oldnorm}{\oldnorm*}}
\makeatother

\author[Author A and Author B]{Tanjim Bin Faruk (1505082) \\ Tanjim Munir (1505083) }
\institute{}
\date{\today}

\setbeamertemplate{title page}{
\begin{minipage}[b][\paperheight]{\textwidth}
\ifx\inserttitlegraphic\@empty\else\usebeamertemplate*{title graphic}\fi
\vfill%
\centering % NEW
\ifx\inserttitle\@empty\else\usebeamertemplate*{title}\fi
\ifx\insertsubtitle\@empty\else\usebeamertemplate*{subtitle}\fi
\usebeamertemplate*{title separator}
\vspace*{10mm}
\ifx\beamer@shortauthor\@empty\else\usebeamertemplate*{author}\fi
\vspace*{20mm} % NEW
\ifx\insertdate\@empty\else\usebeamertemplate*{date}\fi
\ifx\insertinstitute\@empty\else\usebeamertemplate*{institute}\fi
\vfill
\vspace*{1mm}
\end{minipage}
}

\setbeamertemplate{title}{
%  \raggedright%
\centering
\inserttitle%
\par%
\vspace*{0.5em}
}

\begin{document}
\metroset{block = fill}

\begin{frame}
\titlepage
\end{frame}

\vspace{1em}
\only<1>{
\vspace{0.5em}
An adjacency matrix is a square matrix used to represent a finite graph.
\end{block}
\vspace{0.5em}
For a graph with $\mathbold{\abs{V}}$ vertices, an adjacency matrix is a $\mathbold{\abs{V} \times \abs{V}}$ matrix.
\\\vspace{1em}
If the edge between vertex $\mathbold{i}$ and vertex $\mathbold{j}$ is denoted by $\mathbold{V_{i,j}}$ then there are two possibilities.
}

\setbeamertemplate{itemize items}[ball]
\begin{enumerate}
\only<2>{
\item Unweighted Graph
\vspace{1em}
\begin{itemize}
\item Matrix of 0s and 1s where in row $\mathbold{i}$ and column $\mathbold{j}$ is $1$ iff the edge $\mathbold{(i,j)}$ is in the graph
\end{itemize}

$\Scale[1]{ V_{i,j} = \begin{cases} 1 & if ~ edge(i,j) ~ exists \\ 0 & otherwise \end{cases} }$
}
\only<3>{
\item Weighted Graph
\begin{itemize}
\item Edge weight is placed in $\mathbold{V_{i,j}}$ entry if there is an edge and a special value (perhaps \textit{null} to indicate absence of an edge.
\end{itemize}
}
\end{enumerate}

\end{frame}

\end{document}


The problem with your code is that on the first overlay the \begin{enumerate}...\end{enumerate} is already present but not a single item - which is not allowed.

So you have to make sure, that there is no empty enumeration on the first frame.

\documentclass[12pt]{beamer}
\usetheme{metropolis}
\usecolortheme{spruce}

\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{fixmath}
\usepackage{graphicx}

\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%
\newcommand*{\Resize}[2]{\resizebox{#1}{!}{$#2$}}%

\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\DeclarePairedDelimiter\norm{\lVert}{\rVert}%

\begin{document}

\vspace{1em}
\only<1>{
\vspace{0.5em}
An adjacency matrix is a square matrix used to represent a finite graph.
\end{block}
\vspace{0.5em}
For a graph with $\mathbold{\abs{V}}$ vertices, an adjacency matrix is a $\mathbold{\abs{V} \times \abs{V}}$ matrix.
\\\vspace{1em}
If the edge between vertex $\mathbold{i}$ and vertex $\mathbold{j}$ is denoted by $\mathbold{V_{i,j}}$ then there are two possibilities.
}

\only<2-3>{
\setbeamertemplate{itemize items}[ball]
\begin{enumerate}
\only<2>{
\item Unweighted Graph
\vspace{1em}
\begin{itemize}
\item Matrix of 0s and 1s where in row $\mathbold{i}$ and column $\mathbold{j}$ is $1$ iff the edge $\mathbold{(i,j)}$ is in the graph
\end{itemize}

$\Scale[1]{ V_{i,j} = \begin{cases} 1 & if ~ edge(i,j) ~ exists \\ 0 & otherwise \end{cases} }$
}
\only<3>{
\item Weighted Graph
\begin{itemize}
\item Edge weight is placed in $\mathbold{V_{i,j}}$ entry if there is an edge and a special value (perhaps \textit{null} to indicate absence of an edge.
\end{itemize}
}
\end{enumerate}
}

\end{frame}

\end{document}

• This does not however solve my problem. I used the \only command because it would technically erase the content and place the content on that slot. So, I want the weighted graph point on the same spot as unweighted graph but on different slides. Using, \item<2> and then \item<3> places weighted edge on the lower part of the page. See the image : imgur.com/a/UEiyW2m – Robur_131 Jul 15 '18 at 14:05
• @Robur_131 see updated answer - however if you only want a single item per slide, I would not bother with all the problems and simply use separate frames (if you need the same frame number, there is an option for that) – user36296 Jul 15 '18 at 14:16