I have the following part of code which gives me java.lang.NullPointerException, I found the source and I know that I declared a variable but set it initially null and later in the program initialized it but I don't know how to give a default value without getting error! The List accepts two different types, Float and RDD.
Here is the part of the code that has problem in it:
case class RPN (sc:SparkContext, vp: VolumeProperty, var stack:List[Either[RDD[(Int, Array[Float])],Float]]) {
def this(s:SparkContext,v:VolumeProperty) = this(s,v,null); //Think here is the problem
def operand(x: Either[RDD[(Int, Array[Float])],Float]) = new RPN(sc,vp,stack = x :: stack) //gives error on this line
and I am getting following error:
Exception in thread "main" java.lang.NullPointerException
How can I solve it!
Use Nil instead of null. Nil is an empty list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With