构造函数无法实例化为期望的类型;发现:(T1,T2,T3,T4,T5)

时间:2016-10-29 19:06:36

标签: scala spark-graphx

我是spark-graphx和scala的新手。 我写这个方法来验证目标顶点的分数是否已经改变。

 def IsGoalVertexFound(graph: Graph[(VertexId,(Int,Float,Float,Float,String)),Float],goalVertex:(VertexId,(Int,Float,Float,Float))): Boolean ={
        var IsgoalFound:Boolean=false
        var targetVertex=graph.vertices.filter{ case (id,(_,gScore,_,_,_)) => id == goalVertex._1 && gScore!=Float.PositiveInfinity}
          if(targetVertex.isEmpty())
            IsgoalFound=true
        return IsgoalFound
      }

我收到此错误:

Error:(41, 54) constructor cannot be instantiated to expected type;
 found   : (T1, T2, T3, T4, T5)
 required: (org.apache.spark.graphx.VertexId, (Int, Float, Float, Float, String))
    (which expands to)  (Long, (Int, Float, Float, Float, String))
    var targetVertex=graph.vertices.filter{ case (id,(_,gScore,_,_,_)) => id == goalVertex._1 && gScore!=Float.PositiveInfinity}

有什么想法吗? 非常感谢

2 个答案:

答案 0 :(得分:0)

这看起来像序列化错误。尝试将goalVertex._1参数拉出到局部变量中,以便VertexId未序列化:

def IsGoalVertexFound(graph: Graph[(VertexId,(Int,Float,Float,Float,String)),Float],goalVertex:(VertexId,(Int,Float,Float,Float))): Boolean ={
    var IsgoalFound:Boolean=false
    val localGoal = goalVertex._1
    var targetVertex=graph.vertices.filter{ case (id,(_,gScore,_,_,_)) => id == localGoal && gScore!=Float.PositiveInfinity}
      if(targetVertex.isEmpty())
        IsgoalFound=true
    return IsgoalFound
 }

答案 1 :(得分:0)

我尝试了以下解决方案,它运行正常:

System.out.println((int)deg_grp.get(j).get(k));