I don't think this will work, this will only go into the if if categories.size() == 1. Something like this is easier to read, and does the length check before indexing into the array:

    if (!(categories.size() == 1 && (categories[0]=="" || categories[0] =="1")))