Click here to Skip to main content
11,928,985 members (57,513 online)
Rate this:
Please Sign up or sign in to vote.
See more: Java serialport
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 23:17pm
Edited 4-Sep-12 23:33pm
Joan Murt86.9K

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 | Mobile
Web01 | 2.8.151126.1 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2015
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