ForumsProgramming Forum[Answered] This Java error blew my mind... maybe u can find its cause?

1 6135
dorukayhan
offline
dorukayhan
1,318 posts
Bard

boolean metricUsage;
public void setMetricUsage(String asdf){
if(!asdf.equals(null) && asdf != null && (asdf.equals("yes") || asdf.equals("Yes") || asdf.equals("yES") || asdf.equals("YES") || asdf.equals("YEs"))){metricUsage = true;}
else if(!(!asdf.equals(null) && asdf != null && (asdf.equals("yes") || asdf.equals("Yes") || asdf.equals("yES") || asdf.equals("YES") || asdf.equals("YEs")))){
javax.swing.JOptionPane.showMessageDialog(null, "If it wasn`t a 'no', I assume it is.");
metricUsage = false;
}
}

i swear i got a nullPointerException at that if-else statement... WHY?

edit: oh i forgot to tell that this method was in a subclass with several other methods that were referenced directly with jOptionPanes. i merged the methods and the jOptionPane commands in a constructor and evrything worked

  • 1 Reply
KentyBK
offline
KentyBK
566 posts
Nomad

Because you're calling the equals() method on a null reference. Check this link for reference.

Showing 1-1 of 1