You first have to check if the Actor you get from calling g.get(1l)
exists or not. There is a simple fix to this, change your current if statement to:
if(a != null) {
if((a.toString()).equals("Infectious Rock")){
}else if((a.toString()).equals("Infectious Bug")){
}else{
a.removeSelfFromGrid();
}
} else
break;
Adding the extra !=null
check should do the trick, and if not leave a comment and I'll do my best to update the answer.