Error during generated code invocation: com.intellij.debugger.engine.evaluation.EvaluateException: Method threw 'java.lang.IllegalAccessError' exception.

时间:2023-03-08 16:25:40

场景描述:

  再从该数据库中读取数据进行处理的时候,需要将某个字段加入到一个动态的map中,然后需要对该map进行filter过滤,在执行过滤方法的时候报错

Error during generated code invocation:
com.intellij.debugger.engine.evaluation.EvaluateException: Method threw 'java.lang.IllegalAccessError' exception.

  报错截图:

  Error during generated code invocation:  com.intellij.debugger.engine.evaluation.EvaluateException: Method threw 'java.lang.IllegalAccessError' exception.

  也就是说该map执行不了这个方法。

code:

      val maps = Collection.muttable.Map[String, Int]()
for (elem <- referenceData.collect()) {
maps.put(String.valueOf(elem.getAs[Timestamp]("datatime")), elem.getAs[Int]("innum"))
}
val exceptMsgs = auditData.rdd.collect().map(row => {
var auditResult =
val innum = row.getAs[Int]("innum")
//获取数据时间的时分秒
val time = String.valueOf(row.getAs[Timestamp]("datatime")).substring()
//获取对应map中包含这个时间点的数据
val mapArr = maps.filterKeys(_.substring().equals(time)).map(x => x._2)

问题原因:

  上面面代码中,我是将从数据库查询出来的数据"datatime"这个字段进行添加到maps中,而我使用的Timestamp类型,看下我数据库中该字段的类型:

  Error during generated code invocation:  com.intellij.debugger.engine.evaluation.EvaluateException: Method threw 'java.lang.IllegalAccessError' exception.

  数据库中的该字段类型是datetime,本来我以为datetime对应到spark中的类型就是Timestamp,显然这样是会报上面的那个错的,如果当做String类型进行读取也是不行的,完全要按照datetime这个类型来进行修改,否则,数据读取出来之后可以添加到maps中,但是,对maps中的元素进行操作是会有问题的。接下来就是修改

改后部分代码:

val maps = Map[String, Int]()
for (elem <- referenceData.collect()) {
maps.put(String.valueOf(elem.getAs[DateTime]("datatime")), elem.getAs[Int]("innum"))
}
val exceptMsgs = auditData.rdd.collect().map(row => {
var auditResult =
val innum = row.getAs[Int]("innum")
val time = String.valueOf(row.getAs[DateTime]("datatime")).substring()
val mapArr = maps.filterKeys(_.substring().equals(time)).map(x => x._2)

修改之后,问题消失