Java 错误:<;匿名打包柜台$1>;不是抽象的,并且不重写JPacketHandler中的抽象方法nextPackage(JPacket,Object)
在运行从pcaps文件计算数据包的java代码时:强>Java 错误:<;匿名打包柜台$1>;不是抽象的,并且不重写JPacketHandler中的抽象方法nextPackage(JPacket,Object),java,linux,jnetpcap,Java,Linux,Jnetpcap,在运行从pcaps文件计算数据包的java代码时: // Counting the number of packets in pcap files. // User defined package //package jnt; import java.io.File; import org.jnetpcap.Pcap; import org.jnetpcap.packet.JPacket; import org.jnetpcap.packet.JPacketHandler;
// Counting the number of packets in pcap files.
// User defined package
//package jnt;
import java.io.File;
import org.jnetpcap.Pcap;
import org.jnetpcap.packet.JPacket;
import org.jnetpcap.packet.JPacketHandler;
public class PacketCounter {
// Path of the folder having pcap files
// generated by Wireshark(change accordingly)
static String folderpath
= "./pcapfiles/";
static double count = 0;
static double globalcount = 0;
// main function starts here
public static void main(String[] args)
{
// Making the object of a file
// and giving that object address
// of the pcap folder
File file = new File(folderpath);
// Making file array which is used
// to access each file
// inside the folder one-by-one
File[] files = file.listFiles();
// Accessing each file
// one-by-one of files array
for (File f : files) {
// Getting each pcap file name
String FILENAME
= folderpath + f.getName();
// StringBuilder is used to get
// error messages in case
// if any error occurs
StringBuilder errbuf = new StringBuilder();
// Making Pcap object an opening pcap file
// in offline mode and passing pcap filename
// and StringBuilder object to the function
Pcap pcap = Pcap.openOffline(FILENAME, errbuf);
// Here pcap object is used to start a loop
// for capturing each packet of an
// each pcap file(as a pcap file can
// have many packets) one at a time, here -1
// indicates eof(end of file) i.e
// until every packet is captured execute the
// loop, we can also give some value
// instead of -1 which will indicate the
// number of packets to execute
// in each pcap file
pcap.loop(-1, new JPacketHandler() {
// nextPacket is override function
// of JPacketHandler( Handler which is
// use to receive fully decoded packets)
public void nextPacket(JPacket packet,
StringBuilder errbuf)
{
// counter to count the number of packet
// in each pcap file
count++;
}
}, errbuf);
System.out.println("File : " + f.getName()
+ " Number of Packets : "
+ count);
// Global counter to count the total number
// of packets in all pcap file
globalcount = globalcount + count;
count = 0;
}
System.out.println("Total Packets in folder : "
+ globalcount);
}
}
从
javac-cp jnetpcap.jar PacketCounter.java
拾取的JAVA选项:-Dawt.useSystemAAFontSettings=on-Dswing.aatext=true
java:64:错误:不是抽象的,并且不重写JPacketHandler中的抽象方法NextPackage(JPacket,Object)
循环(-1,新的JPacketHandler(){
^
注意:PacketCounter.java使用未经检查或不安全的操作。
注意:使用-Xlint重新编译:未选中以获取详细信息。
1错误
请帮我运行这个代码
操作系统:Kali linux
Java版本:openjdk 11.0.11-ea 2021-04-20
OpenJDK运行时环境(构建11.0.11-ea+4-post-Debian-1)
OpenJDK 64位服务器VM(build 11.0.11-ea+4-post-Debian-1,混合模式,共享)您正在覆盖
NextPackage(JPacket,String)
,但父级需要NextPackage(JPacket,Object)
,检查JPacketHandler
的API……您好,先生,您能说明我在这里可以做些什么来解决这个错误吗?我是java新手。
javac -cp jnetpcap.jar PacketCounter.java
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
PacketCounter.java:64: error: <anonymous PacketCounter$1> is not abstract and does not override abstract method nextPacket(JPacket,Object) in JPacketHandler
pcap.loop(-1, new JPacketHandler() {
^
Note: PacketCounter.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error