Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-14-2007, 09:01 AM
Member
 
Join Date: Aug 2007
Posts: 3
conandor is on a distinguished road
nullPointerException problem
I have this RS232 class that need to read by the main class.
Whenever i use this readData method. it throws nullPointerException message.
but if i implement it d RS232() main method, it works well with output interger value -1 or hex value 255.
why izzit like that?


Code:
/** * @(#)RS232.java * * Serial Port Object */ import javax.comm.*; import java.io.*; import java.net.*; public class RS232 { static InputStream in = null; static OutputStream out = null; private static RS232 instance = new RS232(); public static RS232 getInstance() { return instance; } private RS232() { try { System.out.println("Connecting to serial0 at 115200bps"); CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("serial0"); SerialPort sp = (SerialPort)portId.open("DeviceController", 0); sp.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); sp.setFlowControlMode(SerialPort.FLOWCONTROL_NONE); sp.enableReceiveThreshold(1024); sp.enableReceiveTimeout(1000); // Get output and input stream for the serial port InputStream in = sp.getInputStream(); OutputStream out = sp.getOutputStream(); /* int data; data = 0; try { data = in.read(); System.out.println("data"); } catch (IOException ioe) { System.err.println("readData FAIL"); } */ } catch (IOException ioe) { System.err.println("Unable to open an InputStream " + "for the serial port!"); System.exit(1); } catch (NoSuchPortException nspe) { System.err.println("No Such Port"); System.exit(2); } catch (UnsupportedCommOperationException ucoe) { System.err.println("Unable to set the paramets of the serial port!"); System.exit(3); } catch (PortInUseException piue) { System.err.println("The serial port is in use!"); System.exit(4); } public int readData() { int data; data = 0; try { data = in.read(); System.out.println("data"); } catch (IOException ioe) { System.err.println("readData FAIL"); } return data; } public void sendData(int b) { try { out.write((byte)b); } catch (IOException ioe) {} } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-14-2007, 02:22 PM
Member
 
Join Date: Aug 2007
Posts: 3
conandor is on a distinguished road
problem solved. pls close thread. tq
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
NullPointerException ravian New To Java 2 12-07-2007 05:20 PM
NullPointerException Feng New To Java 5 11-24-2007 08:51 PM
NullPointerException problem warship AWT / Swing 5 08-10-2007 05:43 PM
ERROR: nullPointerException mathias New To Java 1 08-05-2007 07:54 AM
java.lang.NullPointerException Felissa Advanced Java 1 07-05-2007 07:02 AM


All times are GMT +3. The time now is 05:08 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org