Javax run time error NullPointer from method " public void serialEvent( )"
hi lads, i got two pc commicate with each other through serial cable, but on the receiver end, i need 2 classes, class A is for taking the incoming data and put them into an array X, and the other class B will access the array X and taking the content out for further processing.
in class A, there is a method called "public void serialEvent(SerialPortEvent event)", inside this method, whenever data is available on the inputstream, they will be saved into an array X, also B will appear in here as well to access X, the code looks like the following,
public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
try {
while (inputStream.available() > 0) {
inputStream.read(tempBuffer);
X =A.storeInArray(tempBuffer);
B.accessX (X);//////Problems occurred!!!!!!!!
}
} catch (IOException e) {}
break;
}
}
At B.accessX (X), a run time error "NullPointerException" occurred, could anyone help me for that please? thanks in advance
[1417 byte] By [
nerdEvera] at [2007-11-27 10:57:06]

# 3
> Thanks for replying...
>
> In the program, i didnt use B, it is a long name that
> is called Receiverr, and it was intialized
> inside the constructor of A that is called
> BTManager in the program. Sorry about the
> confusion that i made.
Cool. Always best to give us as little work as possible to do!
But my other point still stands - B (or it's namesake) is null
# 9
You have to find out which object is null. You can start by using
...
(if b==null || X==null) {
System.out.println("b: "+b+", X: "+X);
System.exit(1);
}
b.accessX(X);
...
You should also use the stack trace to identify which line exactly causes the exception. You can post the exception trace here, if you cannot find it your self.
# 10
> tanx georgemc,
>
> i tried different names for B, but didnt really work
LOL sorry, no, I mean use clearer names so we can understand it better! It won't fix your problem. The reference 'B' is null, but you know that now :-)
Post the constructor of the A class. B can't be getting initialized, as you claim, or it wouldn't be null
# 11
You have to find out which object is null. You can start by using
...
(if b==null || X==null) {
System.out.println("b: "+b+", X: "+X);
System.exit(1);
}
b.accessX(X);
...
tanx 4 ur effort, i did try that, and the system exits because b is null and it never go down to "b.accessX (X)", how can i make it not null?