I try to predict with a simplified KNN model using the caret package in R. It always gives the same error, even in the very simple reproducible example here:
The problem is your y variable. When you are asking for the class probabilities, the train and / or the predict function puts them into a data frame with a column for each class. If the factor levels are not valid variable names, they are automatically changed (e.g. "0" becomes "X0"). See also this post.
If you change this line in your code it should work:
a[,1] = factor(a[,1], labels = c("no", "yes"))