java.lang.NullPointerException: jmemory not initialized

1 reply [Last post]
shaheenm
Offline
Joined: 08/30/2009

I'm using jnetpcap1.2rc5 on a windows platform with Java 6 update 17

I'm writing a capture application to read offline captures that I've captured using jnetpcap on a seperate application. When loading the saved capture file i read the packets from the file as follows


/* capture packets using the Pcap object and pass to the packet capturer */
result = pCapturer.dispatch(100, bufHandler, "PacketCapturer");

and the code is packet is processed by the JBufferHandler

In the nextPacket method I scan for Ethernet and check if the packet is an IP packet with

public void nextPacket( PcapHeader pheader, JBuffer jbuffer, String t ){
....
/* scan the packet to determine what data it contains */
pkt.scan( Ethernet.ID );

/* check if it is an IP packet */
if ( pkt.hasHeader( ip ) ) {
....
}

When i try to get a value from the last captured packet i get the exception

Exception in thread "Thread-4" java.lang.NullPointerException: jmemory not initialized
at org.jnetpcap.nio.JMemory.size(JMemory.java:457)

I'm at a loss to understand why this happens and why only on the last captured packet. By using pkt.hasHeader(ip), doesnt the IP data get scanned and decoded? and shouldn't it be available for reading right away?

Any help in understanding this would be appreciated.

Thanks
Shaheen

Mark Bednarczyk
Mark Bednarczyk's picture
Offline
Joined: 03/22/2008
You you are using it

You you are using it correctly. hasHeader first checks to see if the header is found and then in a second step peers your ip instance with the packet buffer.

Exactly which line does the exception occur? I can't tell which line 457 is. This looks like a bug in 1.2.rc5.

Any particular reason you are using such an old release? I would recommend that you upgrade to latest 1.3 or if you are adventurous try out latest 1.4 dev build. Both are very stable and 1.3 is about to become production quality with no known bugs in either release.

Sly Technologies, Inc.
R&D

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.