This discussion is archived
2 Replies Latest reply: May 13, 2011 12:49 PM by jschellSomeoneStoleMyAlias RSS

NullPointerException when get serial port.

FanXiaogang Newbie
Currently Being Moderated
Hi,

I use the comm.jar to get serial port, but failed.

error log:
java.lang.NullPointerException: name can't be null
at java.io.FilePermission.init(FilePermission.java:171)
at java.io.FilePermission.<init>(FilePermission.java:249)
at java.lang.SecurityManager.checkDelete(SecurityManager.java:990)
at javax.comm.CommPortIdentifier.getPortIdentifiers(CommPortIdentifier.java:24)

I check the code in comm.jar.

public static Enumeration getPortIdentifiers()
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkDelete(propfilename);
return new CommPortEnumerator();
}

Because securitymanager is not null, invoke checkDelete(propfilename) method. If securitymanager is null, it is all right.

Questions:
1.what is the SecurityManager function here, is the value default null?
2.I put the comm.jar in my class path, also refer the win32com.dll file. But what is the reason for the error?

Thanks in advance!

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points