Take a look Try-Catch, NumberFormatException, nullPointerException
Use try catch
to handle the Exception
Try this, because you got the value as null
. so check the passing value should not be null
try
{
a = Integer.parseInt(s1 != null ? s1 : "0");
b = Integer.parseInt(s2 != null ? s2 : "0");
c = Integer.parseInt(s3 != null ? s3 : "0");
d = Integer.parseInt(s4 != null ? s4 : "0");
}
catch(NumberFormatException ex)
{
System.out.println("Exception : "+ex);
}
And also the variable s is also null
so you got the NullPointerException
if (s != null && s.equals("red"))
instead of
if (s.equals("red"))