JGraphT 在通过 ClassBasedVertexFactory 初始化 case 类 时抛出 NoSuchMethodException
JGraphT throws NoSuchMethodException when initializing case classes through ClassBasedVertexFactory
JGraphT 的 ClassBasedVertexFactory.createVertex()
正在为我的案例 classes 的构造函数抛出 NoSuchMethodException
。 (运行时报告未找到 TJunction.<init>()
。)
这是我的 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
}
}
后面是我的一个案例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
}
这里是我创建顶点的地方:
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)
从我的案例中删除自定义构造函数 class 并将其替换为后续属性的设置器就可以了。
感谢@Marco13 富有启发性的评论。
JGraphT 的 ClassBasedVertexFactory.createVertex()
正在为我的案例 classes 的构造函数抛出 NoSuchMethodException
。 (运行时报告未找到 TJunction.<init>()
。)
这是我的 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
}
}
后面是我的一个案例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
}
这里是我创建顶点的地方:
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)
从我的案例中删除自定义构造函数 class 并将其替换为后续属性的设置器就可以了。
感谢@Marco13 富有启发性的评论。