How to solve this problem
public class DoubleTest {
public static void main(String[] args) {
double dbl = (Double) null;
String str = Double.toString(dbl);
System.out.println(str);
}
}
With Error:
Exception in thread "main" java.lang.NullPointerException
at test.java.DoubleTest.main(DoubleTest.java:6)
Any idea please?
I am asking this because I have a method that return Double which I have to convert to String again.
If my method returns null, then this problem happens.
If you have a method returning null like this:
Then you can have Double to String conversion like this: