Results 1 to 3 of 3
  1. #1
    vasavi.singh is offline Member
    Join Date
    Feb 2009
    Posts
    24
    Rep Power
    0

    Default java.lang.NullPointerException

    Hi,

    In my program I am trying to access the variable of other class. But it is giving NullPoinerException.

    LinearThresholdModel.java

    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;
    import java.io.*;
    import java.util.*;

    public class LinearThresholdModel
    {
    SocialNetworkCons network=new SocialNetworkCons();
    public void methodImplementation(int authorCount)
    {
    int j=0,activeNodes[]=new int[50];
    System.out.println(network.networkIds);
    System.out.println(network.networkIds[0].getNetworkId());
    System.out.println("AuthorCount: "+authorCount);

    for(int i=0;i<=authorCount;i++)
    {
    System.out.println("Method Implementation"); // till this point executes well
    int degree=network.author[i].getDegree(); // raising exception
    System.out.println("Degree: "+degree);
    System.out.println("The count of active nodes in the network are "+j);
    }
    }

    The above method "methodImplementation()" is called in Main.java

    Main.java

    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;
    import java.io.*;
    import java.util.*;

    public class Main
    {
    public static void main(String args[]) throws IOException
    {
    StoreDataInAFile fileObj=new StoreDataInAFile();
    SocialNetworkCons network=new SocialNetworkCons();
    // fileObj.writeDataIntoAFile();
    String data[]=fileObj.readDataFromAFile();
    int authorsId[]=new int [20],temp=-1;
    LinearThresholdModel model=new LinearThresholdModel();

    System.out.println("Number of elements: "+data.length);
    int authorCount=network.constructingSocialNetwork(data );
    System.out.println("Author Count: "+authorCount);
    model.methodImplementation(authorCount);
    }
    }

    can u help me regarding this

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    are you sure SocialNetworkCons object "network" in two difference classes are the same?

  3. #3
    itsmegb is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default

    Java Code:
    int degree=network.author[i].getDegree(); // raising exception
    It looks like maybe author has no contents. is it being initialised?

    Without seeing the contents of SocialNetworkCons() its hard to be sure.

    hope that helps!

    p.s. please use the Code tags next time!

    George

Similar Threads

  1. java.lang.NullPointerException Error
    By Manfizy in forum NetBeans
    Replies: 3
    Last Post: 02-24-2011, 06:27 AM
  2. java.lang.NullPointerException
    By stevemcc in forum AWT / Swing
    Replies: 2
    Last Post: 02-08-2008, 09:01 AM
  3. java.lang.NullPointerException
    By ravian in forum New To Java
    Replies: 1
    Last Post: 01-13-2008, 07:39 PM
  4. Replies: 2
    Last Post: 07-16-2007, 06:21 AM
  5. java.lang.NullPointerException
    By Felissa in forum Advanced Java
    Replies: 1
    Last Post: 07-05-2007, 06:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •