如何在Java中访问端口? [英] How to access ports in java ?
本文介绍了如何在Java中访问端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下Java代码访问系统中的端口,并且给出了空指针异常,任何人都可以帮助我解决此问题.拜托,在此先谢谢
I am trying to access ports in system by using below java code And it is giving null pointer exception can anyone help me to solve this . Please , Thanks in advance
package com.ranju.app;
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
public class Ranjith {
public static void main(String[] args) {
System.out.println("HI ");
Enumeration pList= CommPortIdentifier.getPortIdentifiers();
System.out.println(" ++++++++ ");
//while(pList.hasMoreElements()){
CommPortIdentifier commIdfr=(CommPortIdentifier) pList.nextElement();
System.out.println(" *** "+commIdfr.getName());
//}
}
}
推荐答案
Nullpointer发生在哪里?
这是一个描述它的不错的博客文章-甚至包括示例代码:
http://codeglobe.blogspot.de/2009/02/serial-port- communication-in-java.html [ ^ ]
where is the Nullpointer happening?
Here is a pretty good blog entry describing it - even an example code is included:
http://codeglobe.blogspot.de/2009/02/serial-port-communication-in-java.html[^]
这篇关于如何在Java中访问端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文