通过ClassBasedVertexFactory初始化案例类时,JGraphT抛出NoSuchMethodException

时间:2022-01-05 23:10:18

JGraphT's ClassBasedVertexFactory.createVertex() is throwing a NoSuchMethodException for my case classes' constructors. (The runtime reports that as TJunction.<init>() not being found.)

JGraphT的ClassBasedVertexFactory.createVertex()为我的case类的构造函数抛出NoSuchMethodException。 (运行时报告为未找到TJunction。 ()。)

Here is my parent class:

这是我的父类:

package org.uom.fyp.engine

   class Node {

     private var nType: RoadStructure.EnumVal = RoadStructure.Default

     /**
      * Returns the node's type. (e.g.: <b>RoadStructure.Default</b>)
      */
     def nodeType: RoadStructure.EnumVal = nType

     /**
      * Sets the node's type.
      * @param nType The node's type.
      */
     def nodeType_(nType: RoadStructure.EnumVal) = {
       this.nType = nType
     }

   }

Followed by one of my case classes:

其次是我的一个案例类:

   package org.uom.fyp.engine

   case class TJunction(p: Edge, c1: Edge, c2: Edge) extends Node {
     val priority = p
     val converging1 = c1
     val converging2 = c2
   }

Here is where I'm creating my vertices:

这是我创建顶点的地方:

 def createLaneSlice(network: RoadNetwork, start: Node = null, edgeType: RoadStructure.EnumVal): Edge = {
  var vertexFactory: ClassBasedVertexFactory[Node] = null
  if (edgeType == RoadStructure.TJunction) {
    vertexFactory = new ClassBasedVertexFactory(classOf[TJunction])
  } else if (edgeType == RoadStructure.Roadabout) {
    vertexFactory = new ClassBasedVertexFactory(classOf[Roundabout])
  } else if (edgeType == RoadStructure.Crossroads) {
    vertexFactory = new ClassBasedVertexFactory(classOf[Crossroads])
  } else {
    vertexFactory = new ClassBasedVertexFactory(classOf[Node])
  }

  var v1: Node = null
  if (start == null) {
    v1 = vertexFactory.createVertex()
  } else {
    v1 = start
  }
  val v2: Node = vertexFactory.createVertex()
  network.addVertex(v1)
  network.addVertex(v2)

1 个解决方案

#1


0  

Removing the custom constructor from my case class and replacing it by setters for the subsequent properties does the trick.

从我的case类中删除自定义构造函数并将其替换为后续属性的setter就可以了。

Thanks to @Marco13 for his enlightening comment.

感谢@ Marco13的启发性评论。

#1


0  

Removing the custom constructor from my case class and replacing it by setters for the subsequent properties does the trick.

从我的case类中删除自定义构造函数并将其替换为后续属性的setter就可以了。

Thanks to @Marco13 for his enlightening comment.

感谢@ Marco13的启发性评论。