0

I have a jtable and it is returning a NullPointerException.

My code looks like this:

     for( int i=0 ;i<rows;++i){ 
       if(Stats.getValueAt(i,2)!=null){ 
         observed[i]=Double.parseDouble(Stats.getValueAt(i,2));
       }
      if(Stats.getValueAt(i,2).equals("  "))
        break;
     }

It still returns NullPointerException if not filled up. How can I stop this?

Aurasphere
  • 3,490
  • 12
  • 37
  • 63
  • It is probably a row where `Stats.getValueAt(i,2)` returns `null`. You do check for that before parsing in the first `if`, but in the second `if` you don't. It might be `null`, and you invoke `equals` on it. – Malte Hartwig May 11 '17 at 12:39
  • @Jens I do not find this duplicate flag very appropriate. Larry obviously understands that you have to check for `null` as you can see in the first `if` statement. It's just that he forgot to check again or move the second statement into the first. – Malte Hartwig May 11 '17 at 12:43

0 Answers0