//This is my Main Class here when i call methodTwo in this class i got numnodes=4 but when i tried to access methodTwo in testclass i got NullPointerException.
package Netica;
import norsys.netica.Environ;
import norsys.netica.Net;
import norsys.netica.NodeList;
import norsys.netica.Streamer;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import NeticaTestCases.HNetTest;
public class HNet {
    private static long startTime = System.currentTimeMillis();
    private static Net net;
    private static NodeList nodes;
    int numNodes;
    public int methodOne() {
        System.out.println("we are in first methodOne");
        return 1;
    }
    public int methodTwo() {
        numNodes = nodes.size();
        System.out.println("we are in 2nd methodTwo");
        return numNodes;
    }
    public static void main(String[] args) {
        try {
            // Read in the net file and get list of all nodes and also Total
            // number of nodes:
            net = new Net(neStreamer("DataFiles/KSA_4_Nodes_noisySum.dne"));
            nodes = net.getNodes();
            HNet temp = new HNet();
            temp.methodOne();
            System.out.println("numNodes========>"+temp.methodTwo());//get 4
        } catch (Exception e) {
        }
    }
}
//this is my testclass
package NeticaTestCases;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.fail;
import Netica.HNet;
public class HNetTest {
    HNet temp;
    @Before
    public void setUp() {
        temp = new HNet ();
    }
    @Test
    public void CheckNumNodes() {
        temp.methodOne();
        System.out.println("numNodes========>"+temp.methodTwo());       
        }   
}
please help me out how to resolve NullPointerException in junit testcases.
 
     
    