Null Pointer Exception:::Please Help

Here is the code that is giving some exceptions.

publicvoid capturePacketsFromDevice()

{

startCaptureThread();

}

publicvoid setCaptureFrame(CaptureFrame frame)

{

this.frame=frame;

}

publicvoid stopCapture()

{

if(isCapturing ==true)

{

stopCaptureThread();

}

}

private Thread captureThread;

privatevoid startCaptureThread()

{

isCapturing =true;

if (captureThread !=null)

return;

try

{

captureThread =new Thread(new Runnable(){

JpcapCaptor jpcap = JpcapCaptor.openDevice(JpcapCaptor.getDeviceList()[3], 2000, false, 200);

publicvoid run()

{

while (captureThread !=null)

{

jpcap.processPacket(1, handler);

Thread.yield();

}

jpcap.close();

jpcap =null;

}

});

}

catch(Exception e)

{

}

-->captureThread.setPriority(Thread.MIN_PRIORITY);

frame.startUpdating();

>captureThread.start();

}

void stopCaptureThread()

{

isCapturing =false;

captureThread =null;

frame.stopUpdating();

}

The Exceptions Are :

Exception in Thread"AWT-EventQueue-0" java.lang.NullPointerException

at PacketCaptor.startCaptureThread (PacketCaptor.java.86)

at PacketCaptor.capturePacketsFromDevice(PacketCaptor.java.38)

I've marked the line numbers as "->"

Please help....

[2999 byte] By [elroydsilvaa] at [2007-11-27 3:12:16]
# 1
Your problem is probably right herecatch(Exception e){}insert an e.printStatckTrace() there and then tell us if you get an exception there.
masijade.a at 2007-7-12 8:14:45 > top of Java-index,Core,Core APIs...
# 2
Is there any problem with the Thread sequence and the variable captureThread.?
elroydsilvaa at 2007-7-12 8:14:45 > top of Java-index,Core,Core APIs...
# 3
The only thing I can say at the moment is that captureThread might be null, but if it is it is because an exception is captured and ignored when it is defined.Make the above change, run it again, then tell us what happened.
masijade.a at 2007-7-12 8:14:45 > top of Java-index,Core,Core APIs...
# 4
JpcapCaptor jpcap = JpcapCaptor.openDevice(JpcapCaptor.getDeviceList()[3], 2000, false, 200);This gives an array out of bounds exception : 3I have checked the network devices using NetworkInterface and i have to listen on the 4th one that is the [3] one.
elroydsilvaa at 2007-7-12 8:14:45 > top of Java-index,Core,Core APIs...
# 5

> JpcapCaptor jpcap =

> JpcapCaptor.openDevice(JpcapCaptor.getDeviceList()[3],

> 2000, false, 200);

>

>

> This gives an array out of bounds exception : 3

> I have checked the network devices using

> NetworkInterface and i have to listen on the 4th one

> that is the [3] one.

I must say that this is not a good technique. I don't know that anything in that class guarantees that they will all come back in the same order every time (Hell I don't even know what that class is. Is it yours?).

Why you are getting ArrayIndexOutOfBounds if you are certain that you have four, I don't know, as this means that there are not 4 (or that 4 are not returned even if there is four, or that the user running the program does not have the right to access this info, i.e. as in run from an Applet).

You would be better off getting the list, then cycling through it and finding the one you need, rather than blindly going to the fourth one. Then you can throw an exception if you don't find the one you expect to find.

masijade.a at 2007-7-12 8:14:45 > top of Java-index,Core,Core APIs...