执行下面的代码时出现以下错误。
Object creation impossible, since member nextPacket(PcapPacket,T):void
in org.jnetpcap.packet.PcapPacketHandler is not defined.
如何解决?
while (true) {
val jpacketHandler = new PcapPacketHandler[String] {
def nextPacket(packet: PcapPacket, user: String) {
val data = new KeyedMessage[String, PcapPacket](topic.toString, packet)
println(data)
producer.send(data)
}
}
pcap.loop(50, jpacketHandler, "jNetPcap works!")
}
答案 0 :(得分:0)
以下代码似乎与scala-2.10.4
和jnetpcap-1.3.0
一起使用,这意味着我没有看到问题中报告的任何此类编译时错误:
import org.jnetpcap.packet.PcapPacketHandler
import org.jnetpcap.packet.PcapPacket
object JPCapExample {
class KeyedMessage[K, V](k: K, v: V) {
override def toString() = s"$k -> $v"
}
class Producer[K, V] {
def send(data: KeyedMessage[K, V]) = {}
}
def main(args: Array[String]) {
val producer = new Producer[String, PcapPacket]
val topic = "SomeTopic"
val jpacketHandler = new PcapPacketHandler[String] {
def nextPacket(packet: PcapPacket, user: String) {
val data = new KeyedMessage[String, PcapPacket](topic.toString, packet)
println(data)
producer.send(data)
}
}
}
}
使用了哪个版本的jnetpcap和Scala?