[Solved] Cannot invoke isSelected(); on a primitive type boolean


In posted code

 boolean  grilled = true;
 // ...
 grill = (String) grilled.isSelected();

I suppose you want to get this field instead of that local variable

public class ... {
    JCheckBox grilled;
    //...
}

This is called shadowing. When looking up what that name refers to, the local variable has greater priority than a field, so compiler thinks you are refering to the local variable instead, contradicting your true intention.

You should use this.grilled to refer to the field. Replace grill = (String) grilled.isSelected(); with grill = String.valueOf(this.grilled.isSelected());, assuming your field and your method lives in the same class.

0

solved Cannot invoke isSelected(); on a primitive type boolean