jeudi 15 septembre 2016

java.lang.NoSuchMethodException for Scala Design Patterns

This is a weird issue I'm facing with Scala Design Patterns.

Here's my sample code

trait ReportFactory
object ReportFactory {  
    def apply(reportType : String) = reportType match {
    case "RepA" => new ClassRepA(repDF) 
    case "RepB" => new ClassRepA(repDF)         
    }
}

calling it as

def executeReports(reportType : String) = reportType match {
        case "RepA" =>  ReportFactory("RepA")
        case "RepB" => ReportFactory("RepB")            
        }  

Class Definitions

ClassRepA(reportName : String) extends Serializable with ReportFactory {
//use Dataframe for processing Reports A
}  

ClassRepB(reportName : String) extends Serializable with ReportFactory {
//use Dataframe for processing Report B
}

Issue :
When RepB is executes, I get

java.lang.InstantiationException: com.xxx.ClassRepB

I also see

Caused by: java.lang.NoSuchMethodException: ccom.xxx.ClassRepB.() at java.lang.Class.getConstructor0(Unknown Source) ... 40 more

What am I doing here ??
I generate a DataFrame.. cache it.. and then pass the same DataFrame to subsequent reports depending on the business logic of each Report.

I have tried a log of workarounds like def this() {this()} but nothing seems to be working.
I'm not sure why this error. If anybody has an idea/ suggestions, please let me know , I will try it out.

Aucun commentaire:

Enregistrer un commentaire