急!!!!java进行串口通讯问题,“CommPortIdentifier.getPortIdentifiers()取得端口链表为空”的问题

Gao_TF 2004-11-24 10:02:17
大家好,有个问题问大家,先谢谢!
我想通过java读取GPS信号,但是在第一步java寻找串口时就找不到串口
例子如下(这是从书上抄过来的例子)
import java.io.*;
import java.util.*;
import javax.comm.*;//comm包得到正确配置

public class SimpleRead
{
static CommPortIdentifier portId;
static Enumeration portList; //portList取得机器上所有端口的列表

public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();//问题!!!!!
//portList是空的,经过验证,CommPortIdentifier.getPortIdentifiers()一个端口都没有
while (portList.hasMoreElements())
{
.............
}
..................
}

大家帮我看看是怎么回事啊,我到别人的机器上也了,结果也是一样的,这是为什么呢
谢谢大家
...全文
1456 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
homeland520 2004-11-24
  • 打赏
  • 举报
回复
up
Gao_TF 2004-11-24
  • 打赏
  • 举报
回复
哈哈,已经解决了,是三个包,而我只陪了一个,现在好了,谢谢大家
avaj2004 2004-11-24
  • 打赏
  • 举报
回复
请到sun的网站下载javacomm20-win32.zip文件,
参考里面的配置文档"jdk1.2.html"(在commapi目录下面)

以下是jdk1.2.html文件的部份内容:

Installing the Java Communications API on JDK 1.2 (RC1)
<jdk> refers to the root directory of your JDK installation. If you installed JDK in c:\jdk1.2 then replace all reference to <jdk> with c:\jdk1.2.

1.
Windows: place the win32com.dll in <jdk>\jre\bin directory.

Solaris: put the libSolarisSerialParallel.so in the LD_LIBRARY_PATH.

2.
Place the comm.jar in <jdk>\jre\lib\ext.

3.
Place the javax.comm.properties in <jdk>\jre\lib .

4.
Do not alter the CLASSPATH.

==================
另外:CommPortIdentifier.getPortIdentifiers();不大可能返回NULL,
这里是CommPortIdentifier.java文件的部份源代码:
......
public static Enumeration getPortIdentifiers()
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkDelete(propfilename);
return new CommPortEnumerator();
}
......

CommPortEnumerator类实现了Enumeration接口


shmdhcxy 2004-11-24
  • 打赏
  • 举报
回复
CommPortIdentifier.getPortIdentifiers()
可以这样使用吗!
Gao_TF 2004-11-24
  • 打赏
  • 举报
回复
开发环境就是普通的jdk,j2se1.4.2,用 editplus编写。我到同学的机器上也试过jbuilder
程序很短,就是那个nullpointerException
说是得不到具体的CommPortIdentifier
bfox 2004-11-24
  • 打赏
  • 举报
回复
mark
avaj2004 2004-11-24
  • 打赏
  • 举报
回复
1:说说你的开发环境?
2:程序是否有异常?

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧