scala中的case类给了我运行时异常

时间:2016-09-07 04:43:25

标签: scala

我有一个案例类

case class AGG_RECON(SUBSCRIBER_ID:String , ChargingID:String ,NodeID:String, START_TIME:String, DXE_First_Report_Time:String, DXE_Last_Report_Time:String, DXE_Session_Start_Time:String, DXE_Bearer_Creation_Time:String, DXE_IMSI:String, DXE_MSISDN:String, DXE_RAT_Type:String,
                  DXE_Subscriber_Type:String, DXE_VPMN:String, DXE_ROAM_TYPE:String, DXE_APN:String, DXE_APN_Category:String, DXE_Charging_Characteristics:String, DXE_CDR_Count:String,
                  NW_First_Report_Time:String, NW_Last_Report_Time:String, NW_Session_Start_Time:String, NW_IMSI:String, NW_MSISDN:String, NW_RAT_Type:String, NW_ROAM_TYPE:String, NW_APN:String, NW_APN_Category:String, NW_Charging_Characteristics:String, NW_CDR_Count:String,
                  CHG_First_Report_Time:String, CHG_Last_Report_Time:String, CHG_Session_Start_Time:String, CHG_IMSI:String, CHG_MSISDN:String, CHG_ROAM_TYPE:String, CHG_APN:String,
                  CHG_APN_Category:String, CHG_Charging_Characteristics:String, CHG_Rate_Plan:String, CHG_Rating_Group:String, CHG_CDR_Count:String, VOL_PROBE_UL_VOL:String, VOL_PROBE_DL_VOL:String, VOL_PROBE_FREE_VOL:String, VOL_PROBE_TOT_VOL:String, VOL_NW_UL_VOL:String,VOL_NW_DL_VOL:String, VOL_NW_FREE_VOL:String, VOL_NW_TOT_VOL:String, VOL_CHG_UL_VOL:String,
                  VOL_CHG_DL_VOL:String, VOL_CHG_FREE_VOL:String, VOL_CHG_TOT_VOL:String, VOL_DXE_Session_End_Time:String, VOL_NW_Session_End_Time:String,
                  VOL_CHG_Session_End_Time:String, VOL_Session_Closed_Time:String, VOL_DXE_Is_Completed:String, VOL_NW_Is_Completed:String, VOL_CHG_Is_Completed:String, VOL_Is_Closed:String, VOL_Session_Category:String)


{
 override def toString(): String = {
val result = s"AGG_RECON_SUBSCRIBER_ID=${SUBSCRIBER_ID}, AGG_RECON_ChargingID=${ChargingID} ,AGG_RECON_NodeID=${NodeID}, AGG_RECON_START_TIME=${START_TIME}" +
  s"AGG_RECON_DXE_First_Report_Time=${DXE_First_Report_Time}, AGG_RECON_DXE_Last_Report_Time=${DXE_Last_Report_Time}, AGG_RECON_DXE_Session_Start_Time=${DXE_Session_Start_Time}, AGG_RECON_DXE_Bearer_Creation_Time=${DXE_Bearer_Creation_Time}," +
  s"AGG_RECON_DXE_IMSI=${DXE_IMSI}, AGG_RECON_DXE_MSISDN=${DXE_MSISDN}, AGG_RECON_DXE_RAT_Type=${DXE_RAT_Type}," +
  s"AGG_RECON_DXE_Subscriber_Type=${DXE_Subscriber_Type}, AGG_RECON_DXE_VPMN=${DXE_VPMN}, AGG_RECON_DXE_ROAM_TYPE=${DXE_ROAM_TYPE}, AGG_RECON_DXE_APN=${DXE_APN}, AGG_RECON_DXE_APN_Category=${DXE_APN_Category}," +
  s"AGG_RECON_DXE_Charging_Characteristics=${DXE_Charging_Characteristics}, AGG_RECON_DXE_CDR_Count=${DXE_CDR_Count}," +
  s"AGG_RECON_NW_First_Report_Time=${NW_First_Report_Time}, AGG_RECON_NW_Last_Report_Time=${NW_Last_Report_Time}, AGG_RECON_NW_Session_Start_Time=${NW_Session_Start_Time}, AGG_RECON_NW_IMSI=${NW_IMSI}, AGG_RECON_NW_MSISDN=${NW_MSISDN}, AGG_RECON_NW_RAT_Type=${NW_RAT_Type}, AGG_RECON_NW_ROAM_TYPE=${NW_ROAM_TYPE}, " +
  s"AGG_RECON_NW_APN=${NW_APN}, AGG_RECON_NW_APN_Category=${NW_APN_Category}, AGG_RECON_NW_Charging_Characteristics=${NW_Charging_Characteristics}, AGG_RECON_NW_CDR_Count=${NW_CDR_Count},"+
  s"AGG_RECON_CHG_First_Report_Time=${CHG_First_Report_Time}, AGG_RECON_CHG_Last_Report_Time=${CHG_Last_Report_Time}, AGG_RECON_CHG_Session_Start_Time=${CHG_Session_Start_Time}, AGG_RECON_CHG_IMSI=${CHG_IMSI}, AGG_RECON_CHG_MSISDN=${CHG_MSISDN}, AGG_RECON_CHG_ROAM_TYPE=${CHG_ROAM_TYPE}, " +
  s"AGG_RECON_CHG_APN=${CHG_APN},"+
  s"AGG_RECON_CHG_APN_Category=${CHG_APN_Category}, AGG_RECON_CHG_Charging_Characteristics=${CHG_Charging_Characteristics}, AGG_RECON_CHG_Rate_Plan=${CHG_Rate_Plan}, AGG_RECON_CHG_Rating_Group=${CHG_Rating_Group}, AGG_RECON_CHG_CDR_Count=${CHG_CDR_Count}," +
  s"AGG_RECON_VOL_PROBE_UL_VOL=${VOL_PROBE_UL_VOL}, AGG_RECON_VOL_PROBE_DL_VOL=${VOL_PROBE_DL_VOL}, AGG_RECON_VOL_PROBE_FREE_VOL=${VOL_PROBE_FREE_VOL}, AGG_RECON_VOL_PROBE_TOT_VOL=${VOL_PROBE_TOT_VOL}, AGG_RECON_VOL_NW_UL_VOL=${VOL_NW_UL_VOL},AGG_RECON_VOL_NW_DL_VOL=${VOL_NW_DL_VOL}, " +
  s"AGG_RECON_VOL_NW_FREE_VOL=${VOL_NW_FREE_VOL}, AGG_RECON_VOL_NW_TOT_VOL=${VOL_NW_TOT_VOL}, AGG_RECON_VOL_CHG_UL_VOL=${VOL_CHG_UL_VOL}," +
  s"AGG_RECON_VOL_CHG_DL_VOL=${VOL_CHG_DL_VOL}, AGG_RECON_VOL_CHG_FREE_VOL=${VOL_CHG_FREE_VOL}, AGG_RECON_VOL_CHG_TOT_VOL=${VOL_CHG_TOT_VOL}, AGG_RECON_VOL_DXE_Session_End_Time=${VOL_DXE_Session_End_Time}, AGG_RECON_VOL_NW_Session_End_Time=${VOL_NW_Session_End_Time}," +
  s" AGG_RECON_VOL_CHG_Session_End_Time=${VOL_CHG_Session_End_Time}, AGG_RECON_VOL_Session_Closed_Time=${VOL_Session_Closed_Time}, AGG_RECON_VOL_DXE_Is_Completed=${VOL_DXE_Is_Completed}," +
  s"AGG_RECON_VOL_NW_Is_Completed=${VOL_NW_Is_Completed}, AGG_RECON_VOL_CHG_Is_Completed=${VOL_CHG_Is_Completed}, AGG_RECON_VOL_Is_Closed=${VOL_Is_Closed}, AGG_RECON_VOL_Session_Category=${VOL_Session_Category}"
result


}
}

当我执行我的应用程序时,这个类在编译时没有给我任何错误,它给了我

"除了类或对象定义"在toString方法之前的第一个括号上..我正在使用scala 2.11.5 ..我真的不知道是什么问题?

1 个答案:

答案 0 :(得分:5)

  1. 不,它是编译错误,而不是运行时异常。

  2. 类主体之前的空行告诉编译器

    case class AGG_RECON(...)
    

    是完整的定义,

    { 
      override def toString = ...
    }
    

    是一个不相关的块,但您不能在Scala文件的顶层有块。删除){之间的行,一切都会有效。