I am getting a null pointer exception despite checking with an if statement first whether the value is null. Here is my code:
Collections.sort(taskList,new Comparator<Task>(){ //here is one NPE
@Override
public int compare(Item t1,Item t2){
if((t1.getAssignedString()!=null)&&(t2.getAssignedString()!=null)){ //here is second NPE
int x=t1.getAssignedString().compareTo(t2.getAssignedString());
if(x!=0){return x;}
else{
Integer x1=(int)(4*(((Task)t1).getAllottedTime()));
Integer x2=(int)(4*(((Task)t2).getAllottedTime()));
return x1.compareTo(x2);
}
}
else{System.out.println("null value");
return 0;}
}
});
Why is this check not working? Is there a way round this?
t1.getAssignedString(), but nott1.