Null pointer exception
<pre><code> public static void main(String[] args) {
        // TODO Auto-generated method stub

        Scanner sc = new Scanner(System.in);
        int source= sc.nextInt();
        int dest  =  sc.nextInt();
        int noOfVertices= sc.nextInt();
        int noofEdges= sc.nextInt();
        int GreeLights[] = new int[noOfVertices+1];
        HashMap&lt;edge, Integer&gt; edgeInfo= new HashMap&lt;&gt;();
        Graph g= new Graph();
        for(int i=1;i&lt;=noOfVertices;i++){
            GreeLights[i]=sc.nextInt(); 
        }

        for(int i=1;i&lt;=noofEdges;i++){
            int x= sc.nextInt();
            int y= sc.nextInt();
            int weight= sc.nextInt();
            edge e= new edge(x,y);
            edgeInfo.put(e, weight);
            g.adj.put(x, new LinkedList&lt;Integer&gt;());
            g.addNeighbour(x, y);
        }

        boolean visited[]= new boolean[noOfVertices+1];
        int distance[]= new int[noOfVertices+1];

        for(int i=1;i&lt;=noOfVertices;i++){
            visited[i]=false;
            distance[i]=1000;
        }

        distance[source]=0;

        for(int i=1;i&lt;=noOfVertices;i++){
            int min=1000;
            int minIndex=-1;
            for(int j=1;j&lt;=noOfVertices;j++){
                if(distance[j]&lt;min){
                    min=distance[j];
                    minIndex=j;
                }
            }               
            visited[minIndex]=true;
            LinkedList&lt;Integer&gt; LL= g.getNeighbors(minIndex);
            for(int x:LL){
                if(visited[x]!=true){
                    edge e = new edge(minIndex,x);
                    int weightofEdge=edgeInfo.get(e); //Null pointer exception occuring here
                    int distancetoNeighbour =    
              distance[minIndex]+weightofEdge;
                    if(distance[x]&gt;distancetoNeighbour){
                        int greenTime=GreeLights[x];
                        int wait=0;
                        for(int j=0;j&lt;distancetoNeighbour;){
                            j=j+greenTime;
                            wait=j;
                        }
                        wait-=distancetoNeighbour;
                        if(wait==0){
                            distance[x]=distancetoNeighbour;
                        }
                        else{
                            distance[x]=distancetoNeighbour+wait;
                        }
                    }
                }
            }
        }


        System.out.println(distance[dest]);

    }
</code></pre>

<p>I created a hashmap to store the edge as key and the weight of that edge as value. Now applied Dijkstras algorithm to solve my problem in which I need to get the weight value corresponding to an edge. So I make a new edge having vertices same as the required edge present in the hashmap but when I call edgeInfo.get() function to get the weight value of that edge it shows NullPointerException...can anyone help me..</p>

<p>My edge class is :-</p>

<pre><code>  class edge{
  int x;
 int y; 

 public edge(int x,int y){
    this.x=x;
    this.y=y;

}

public boolean equals(edge e){
    return (this.x==e.x &amp;&amp; this.y==e.y);
}   

 }
</code></pre>