In my program I need to create a new node and adding that to a specified network. I need to access that network to find the neighbors of the nodes. Here the problem I am getting is NullPointerException. Why it is raising the exception I understood the point. How to solve it I am not getting. Can u people help me regarding this problem.


I am creating the node like this.
//Naming a network.
CommunicationNetworkId[] networkIds = { new CommunicationNetworkId("Academics") };
AcademicsAgents agent[]=new AcademicsAgents[500];
Author author[]=new Author[1000];
//Adding nodes to that network
agent[m]=new AcademicsAgents(name,cite,yr,a_count,ref,0); // article node creation
simulation.addAgent(agent[m], networkIds); // adding to the network
author[n]=new Author(name,0,pub,loc,dept,0,0,0,0); // same for author nodes
simulation.addAgent(author[n], networkIds);

Establishing connection between the authors and the author - article nodes

In the Main Program all this procedure is called by using a method


Later we need to find the neighbors of all nodes. That will be done by calling the method

Here network is the object of the SocialNetworkCons class. I am sending the entire network to the function.

For finding the neighbors of the nodes the method is getNeighbors(). For this method we need to send the network Id which is created initially and the method returns the neighbors list as type of List.

Here I am getting the problem

IEnvironment env = sensor.getEnvironment(); // getting the environment
CommunicationNetworkId networkId = env.getNetworkIds()[0]; // getting the networkId
List neighbors = env.getNeighbors(networkId); // passing it to the function

What the error I am getting is NullPointerException.

Later I changed it to
IEnvironment env = sensor.getEnvironment(); // getting the environment
CommunicationNetworkId networkId = network.networkIds[0];

I am sending that CommunicationNetworkId varialble as parameter to getNeighbors() function. Here also it is raising the same exception.

I don't no how to solve it.

and I have one more doubt about the storage of the neighbor information as a List.
From that List I need access a particular node neighbors information. In which sequence it is giving the neighbors list is I don't no. I saw the get() for which we need to pass the index number to get that information. But we don't now the index even. So, how to do it.

Please respond fast.

Best regards,