Click here to Skip to main content
13,506,337 members
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


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(" ++++++++ ");
CommPortIdentifier commIdfr=(CommPortIdentifier) pList.nextElement();
System.out.println(" *** "+commIdfr.getName());


Posted 4-Sep-12 22:17pm
Updated 4-Sep-12 22:33pm

1 solution

Rate this: bad
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:[^]
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 |
Web01 | 2.8.180417.1 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2018
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