JGraphT's ClassBasedVertexFactory.createVertex()
бросает NoSuchMethodException
для конструкторов классов case. (Среда сообщает, что, как TJunction.<init>()
не найден.)JGraphT бросает NoSuchMethodException при инициализации классов классов через ClassBasedVertexFactory
Вот мой родительский класс:
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)
Я не знаком с scala, но, очевидно, этот «класс case» thingy не имеет открытого конструктора по умолчанию no-args. Я не уверен, может ли это решить, например, 'def this() = this (null, null, null)' в 'TJunction'. В противном случае вы, вероятно, можете создать свою собственную фабрику вершин. Вам не нужно использовать встроенный 'ClassBased ... '. – Marco13