Iterating over node names in \foreach gives \inaccessible error
Since egreg corrected your code, I simplify it by using loops with a single variable since the other two can be generated by a single variable.
\documentclass[border=5mm,tikz]{standalone}
\usetikzlibrary{shapes,intersections}
\begin{document}
\begin{tikzpicture}
\tikzset{mass/.style={draw, fill=gray!20, cylinder, shape aspect=1, minimum width=1.5cm, minimum height=1cm, shape border rotate=180}}
\foreach \tag[count=\xpos from 0] in {J_1,J_2,J_3,\cdots,J_n}
{
\node[mass, name=J\xpos] at (2*\xpos,0) {};
\draw[shift=(J\xpos.center)] node[] {$\tag$};
}
\foreach \n [evaluate=\n as \lastn using int(\n+1)] in {0,1,2,3}
{
\path[name path=line1] (J\lastn.before top) -- (J\lastn.after top);
\path[name path=line2] (J\lastn.top) -- (J\lastn.bottom);
\draw[name intersections={of=line1 and line2}, thick] (J\n.east) -- (intersection-1);
}
\end{tikzpicture}
\end{document}
You can't use numbers together with letters in control sequences.
A control sequence name can be either a single nonletter or a sequence of one or more letters.
So \name1
is an illegal name in this context and generally; in some situations it could seem to work, but don't count on this.
Use
\foreach \namea/\nameb in {J1/J2, J2/J3, J3/J4, J4/J5}
{
\path[name path=line1] (\nameb.before top) -- (\nameb.after top);
\path[name path=line2] (\nameb.top) -- (\nameb.bottom);
\draw[name intersections={of=line1 and line2}, thick] (\namea.east) -- (intersection-1);
}
Numbers in path or coordinate names are legal, but for completely different reasons.