View Full Version : java comm API problem
shree
10-14-2005, 08:33 AM
hello sir,
i need your help. iam working with java communication API.
iam getting following error.
E:\javacomm>java SimpleWrite
javax.comm.CommPortEnumerator@5ff48b
portId=null
Exception in thread "main" java.lang.NullPointerException
at SimpleWrite.main(SimpleWrite.java:16)
help me please.........
sincerely
shree
KeZZeR
10-14-2005, 01:41 PM
Well that really helps, could we see some code? :rolleyes:
suryad
10-15-2005, 05:26 AM
Yeah put in a posting of code for more help...we are not mind readers unfortunately! :D
shree
10-18-2005, 06:47 AM
hello sir,
iam sending code.
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SimpleWrite {
static CommPortIdentifier portId;
static Enumeration portList;
static String messageString = "at\n";
static SerialPort serialPort;
static OutputStream outputStream;
public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();
System.out.println(portList);
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();System.out.println("portId="+portId);
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM1"))
{
System.out.println(portId.getName());
//if (portId.getName().equals("/dev/term/a")) {
try {
serialPort = (SerialPort)
portId.open("SimpleWriteApp", 2000);System.out.println(portId);System.out.println("at");
} catch (PortInUseException e) {}
try {System.out.println("at");
outputStream = serialPort.getOutputStream();
} catch (IOException e) {}
try { System.out.println("settings");
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
try {System.out.println("at");
outputStream.write(messageString.getBytes());
} catch (IOException e) {}
}
}
}
}
}
it compiled successfully, but when iam trying to run this program
iam getting error like no serial ports for reading program, for writing nullpointer exception.
thank you.
shree
10-18-2005, 01:30 PM
hello sir,
i have sent code.
one thing here i want to mention. iam using windows-2000 Professional.
thank you once again.
pls help me how to solve errors NullPointer Exception and
No serial Ports found.
shree
shree
10-22-2005, 06:46 AM
hello
please help me. iam waiting for your reply.
one thing is i want to mention pls...
the same code which i have sent, it is working in windows-98.
but not in windows 2000 professional.
may be the problem is installing comm.jar and javax.comm.properties.
for w-98, i have placed comm.jar in c:\j2sdk..\jre\lib\ext and properties in c:\j2sdk..\jre\lib.
for w-2000 also i have placed in same places.
but it is not working.
the same error which i have mentioned first. no serial ports found.
if you find answer please help me.
thanking you.
hohonuuli
11-03-2005, 06:24 PM
Did you put the win32com.dll in %JAVA_HOME%/jre/bin? On windows this path will be something like C:Program Files\Java\jdk1.5.0_04\jre\bin.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.