Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

Java
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());

//}
}

}
Posted
Updated 4-Sep-12 22:33pm
v2

1 solution

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[^]
 
Share this answer
 
Comments
ranjith m amin 6-Sep-12 5:58am    
System.out.println(" *** "+commIdfr.getName());
Above line giving exception . I think pList or comIdfr is pointing to null.
Thank you for reply Sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900