Hi,

I am having a class SocialNetworkCons.java. On compilation it is not giving any errors. On running the program it is giving the exception java.lang.NullPointerException. By referring other articles, I understood that trying to a variable having null value. I checked my program to find the error. I am not able to find where I am accessing a variable which is having null value.
The program is as follows:

import jsns.model.CommunicationNetworkId;
import jsns.model.util.ContinuousTime;
import jsns.model.util.LoggingMasterImpl;
import jsns.model.IEnvironment;
import jsns.model.util.EnvironmentImpl;
import jsns.system.SimulationControl;
import java.lang.String;

public class SocialNetworkCons
{
CommunicationNetworkId[] networkIds = { new CommunicationNetworkId("Academics") };
AcademicsAgents agent[]=new AcademicsAgents[1000];
Author author[]=new Author[5000];
static int m=0,n=0;
int p;
int neighborsList[][]=new int[1000][1000];
int weightBetweenAuthors[][]=new int[1000][1000];
int weightBetweenAuthorNArticle[][]=new int [1000][1000];
int authorsId[]=new int [20];

ContinuousTime startTime = new ContinuousTime(0);
ContinuousTime endTime = new ContinuousTime(10);
LoggingMasterImpl logging=new LoggingMasterImpl();

SimulationControl simulation = new SimulationControl(startTime, logging);
IEnvironment env=new EnvironmentImpl();

public int checkNodeIdInNetwork(int mn, String id)
{ // checking of the node whether already exist or not
for(p=0;p<mn;p++) //check upto the index mn
{
String s=agent[p].getId();
if(id.equalsIgnoreCase(s))
{
System.out.println("The entered node ia already in the network with the agent index "+p);
return p; // if it is there returns that index
}
}
return -1; // else -1
}
public int createArticleNode(String[] tkn,int a)
{ // creating the article node
int index=checkNodeIdInNetwork(m,tkn[a]); // checking in the network
if(index == -1)
{
String name=tkn[a]; // storing all data in different varaibles and
int cite=Integer.parseInt(tkn[a+1]); //parsing them to appropriate type
int yr=Integer.parseInt(tkn[a+2]);
int a_count=Integer.parseInt(tkn[a+3]);
String ref=tkn[a+4];

agent[m]=new AcademicsAgents(name,cite,yr,a_count,ref); // passing 2 constructor
simulation.addAgent(agent[m], networkIds); // adding to network
index=checkNodeIdInNetwork(m,tkn[a+4]); //again checking one field of the constructr
if(index != -1) // if exist establising a connection
simulation.addDirectedConnection(agent[m].getId(), agent[index].getId(),networkIds[0]);
else // else displaying appropriate msg
System.out.println("Sorry, the entered reference articles is not exist in the defined
network.");
for(int i=0;i<agent[m].getNoOfAuthors();i++)
{ // reading the data from one field of the new node
int r=a+5+i*4;
int temp=createAuthorNode(tkn,r); //calling the method
authorsId[i]=temp-1; // storing the indexed in an array whether they exist in the
// network are not
System.out.println("The entered node is stored in network with index number
"+authorsId[i]); // displaying with what index node is created
}
createEdgeBetweenAuthors(authorsId,agent[m].getNoOfAuthors()); // establishing connection between the author nodes
System.out.println("The connection are established between the authors");
return (++m); // returning the new index of the article node
}
else
{
System.out.println("No need to add in a network.");
return (index+1); // return the index of node where that info stored in network
}
}
public int createAuthorNode(String[] tkn,int x)
{ // creating the author node
String name=tkn[x]; // reading the data from file
int pub=Integer.parseInt(tkn[x+1]); // converting into appropriate type
String loc=tkn[x+2];
String dept=tkn[x+3];
int index=checkNodeIdInNetwork(n,tkn[x]); // checking the node existence
if(index == -1)
{ // not in the network so create
System.out.println("Entered author is not in the netowrk.");
author[n]=new Author(name,0,pub,loc,dept,0,0,0); //creation of node
simulation.addAgent(author[n], networkIds); //adding to network
//establishment of connection between the initial created and later created node
simulation.addDirectedConnection(author[n].getId(), agent[m].getId(), networkIds[0]);
System.out.println("Connection is established between the author and the article");
weightBetweenAuthorNArticle[n][m]=agent[m].getCitations(); //assign weight 2 edge
System.out.println("Weight of the edge between ar & au is "+
WeightBetweenAuthorNArticle[n][m]);
author[n].setNoOfArticlesPublishedInNetwork(author[n].getNoOfArticlesPublishedInNetwork()+1);
System.out.println("No of articles published in the network: "+
author[n].getNoOfArticlesPublishedInNetwork()); // updating the data with new info
return (++n); // returning new node index (for next node)
}
else
{ // same as above but not creating new node, using the previous info& updating
System.out.println("Entered author is a member of netowrk.");
simulation.addUndirectedConnection(author[index].getId(), agent[m].getId(), networkIds[0]);
System.out.println("Connection is established between the author and the article");
weightBetweenAuthorNArticle[index][m]=agent[m].getCitations();
System.out.println("Weight of the edge between ar & au is
"+weightBetweenAuthorNArticle[index][m]);
author[index].setNoOfArticlesPublishedInNetwork(author[index].getNoOfArticlesPublishedInNetwork()+1);
System.out.println("No of articles published in the network: "+
author[index].getNoOfArticlesPublishedInNetwork());
if(author[index].getNoOfArticlesPublished()< pub)
author[index].setNoOfArticlesPublishedInNetwork(pub);
return (index+1);
}
}
public void createEdgeBetweenAuthors(int authorsId[],int x)
{//establishing the connection between the nodes
int k,l;
for(int i=0;i<x;i++)
{
for(int j=i+1;j<x;j++)
{
k=authorsId[i];
l=authorsId[j];
if(neighborsList[i][j] != 1)
{
simulation.addUndirectedConnection(author[k].getId(), author[l].getId(),
networkIds[0]);
author[i].setDegree(author[i].getDegree()+1);
author[j].setDegree(author[j].getDegree()+1);
weightBetweenAuthors[i][j] += 1;
weightBetweenAuthors[j][i] += 1;
neighborsList[i][j]=1;
neighborsList[j][i]=1;
String s1=author[k].getWorkingPlace();
String t1=author[l].getWorkingPlace();
if(s1.equalsIgnoreCase(t1))
{
weightBetweenAuthors[i][j] += 1;
String s2=author[k].getDept();
String t2=author[l].getDept();
if(s2.equalsIgnoreCase(t2))
weightBetweenAuthors[i][j] += 1;
}
}
else
{
weightBetweenAuthors[i][j] += 1;
weightBetweenAuthors[j][i] += 1;
String s1=author[k].getWorkingPlace();
String t1=author[l].getWorkingPlace();
if(s1.equalsIgnoreCase(t1) && s1 != null || t1 != null)
{
weightBetweenAuthors[i][j] += 1;
String s2=author[k].getDept();
String t2=author[l].getDept();
if(s2.equalsIgnoreCase(t2) && s2 != null || t2 != null)
weightBetweenAuthors[i][j] += 1;
}
}
}
}
}
}

on running it is giving the following error:

Exception in thread "main" java.lang.NullPointerException
at SocialNetworkCons.checkNodeIdInNetwork(SocialNetwo rkCons.java:32)
at SocialNetworkCons.createAuthorNode(SocialNetworkCo ns.java:82)
at SocialNetworkCons.createArticleNode(SocialNetworkC ons.java:62)
at Main.main(Main.java:21)

Initially it is accepting the data and also displaying few lines of output. Later it is raising the error.