JGraphT的ClassBasedVertexFactory.createVertex()
为我的case类的构造函数抛出NoSuchMethodException
。 (运行时报告未找到TJunction.<init>()
。)
这是我的父类:
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
}
}
其次是我的一个案例类:
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
}
这是我创建顶点的地方:
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)
答案 0 :(得分:0)
从我的case类中删除自定义构造函数并将其替换为后续属性的setter就可以了。
感谢@ Marco13的启发性评论。