The Artima Developer Community
Sponsored Link

Java Answers Forum
urgent help needed please

3 replies on 1 page. Most recent reply: Mar 17, 2002 10:52 PM by Swaraj

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Swaraj

Posts: 24
Nickname: swaraj
Registered: Mar, 2002

urgent help needed please Posted: Mar 10, 2002 11:18 PM
Reply to this message Reply
Advertisement
Hi
I am using javax.comm api's serial port events in my application, i am using these events only.
CD,CTS, and DSR. so whenever i fire an event i had to call a method from my base class. my problem is that whenever i call the method i am getting a nullpointer exception, the exception goes like this.

java.lang.NullPointerException

at myComport.serialEvent(TypicalPlayerApplet.java:1951)

at com.sun.comm.Win32SerialPort.sendCTSeventWin32SerialPort.java:559)

at com.sun.comm.NotificationThread.run Win32SerialPort.java:843)

Where TypicalPlayerApplet is my application and myComport is my method which implements serialporteventlistener.

I did not find much information on the web, about this. So i am posting this topic in this forum. Can anybody help me with this.
My serialEvent code is like this..

public void serialEvent(SerialPortEvent ev) {
if(this.port==null)
{
System.out.println(port.getName()+ "got serial event on a closed port");
return;
}
if(port.isCD()) // Carrier Detect
{
System.out.println("Carrier detect called-need to invoke the forward method");
owner.forward();
}
else if(port.isCTS()) // Clear To Send
{
System.out.println("Clear To Send called-need to invoke the reverse method");
owner.reverse();
}
else if(port.isDSR()) // Data Set Ready
{
System.out.println("Data Set Ready called-need to invoke the play method");
owner.play();
}
}

in the above code port is my SerialPort object and owner is the application base class. the methods forward reverse and play are the methods written in side the base class. These work on a java media player.

Please help...

Thanks
Swaraj


Swaraj

Posts: 24
Nickname: swaraj
Registered: Mar, 2002

Re: urgent help needed please Posted: Mar 11, 2002 11:33 PM
Reply to this message Reply
Cant anyone help with this problem?
Then please guide me to a proper forum.

Swaraj

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: urgent help needed please Posted: Mar 12, 2002 10:10 AM
Reply to this message Reply
java.lang.NullPointerException will be generated when some object in the method myComport.serialEvent is null.
The error message cites line 1951 in java file TypicalPlayerApplet.java

You reference an object named owner
several times:
owner.forward();
owner.reverse();
owner.play();
This object may have been decleared somewhere in you program but never ininitialized (instantiated).

You could add a line of debug code in this method to test if it is null and print out a message.

if (owner == null) System.out.prinltn("owner is null");

recompile and run and see if the line gets executed at run time.

or you could add some dummy lines of debug code at several places in the method, recompile
and see which lines get executed before the nullpointerexception.

System.out.println("Got here 111");

System.out.println("Got here 222");

System.out.println("Got here 333");

etc. then delete them when you figure out the problem.

This is the poor man's way of debugging.

My best guess is that owner is not initialized properly.

Swaraj

Posts: 24
Nickname: swaraj
Registered: Mar, 2002

Re: urgent help needed please Posted: Mar 17, 2002 10:52 PM
Reply to this message Reply
Thanks
I got my issue resolved.

Swaraj

Flat View: This topic has 3 replies on 1 page
Topic: TicTacToe Previous Topic   Next Topic Topic: java paths in linux?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use