Click here to Skip to main content
13,247,911 members (46,171 online)
Rate this:
 
Please Sign up or sign in to vote.
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

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 4-Sep-12 23:17pm
Updated 4-Sep-12 23:33pm
Joan M91.9K
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100