fixed NPE exception when getting startIndex from query