nullpointer exception
Can anyone help? when I run the code below, I end up with a
NullPointerException. I figured is because I am trying to do
outputstream.write(cmdstring.getBytes()); on line 46.
I need help figuring out why it gives me an exception. Thanks
Drake01
import java.util.*;
import javax.comm.*;
import java.io.*;
import java.awt.Toolkit;
publicclass Wavetronix
{
static CommPortIdentifier portID;
static Enumeration portlist;
static SerialPort serialport;
static OutputStream outputstream;
static String cmdstring ="Hello World";
publicstaticvoid main(String args[])
{
portlist = portID.getPortIdentifiers();
while (portlist.hasMoreElements())
{
portID = (CommPortIdentifier) portlist.nextElement();
if (portID.getPortType() == CommPortIdentifier.PORT_SERIAL)
{
System.out.println(portID.getName());
if(portID.getName().equals("COM1"))
{
try
{
serialport = (SerialPort) portID.open("WavetronixApp", 2000);
System.out.println("did portID.open return null?" + (serialport ==null));
}catch(PortInUseException e){}
try
{
serialport.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
}catch (UnsupportedCommOperationException e){}
try
{
outputstream.write(cmdstring.getBytes());
}catch (IOException e){System.out.println("unsuccessful write");}
}
}
}
}
}

