Exception in thread "main" java.lang.NullPointerException
<p>I started to learn java yesterday and I wrote the followind program which should print pairs of equal numbers, but when I run it I get </p>

<pre><code>Exception in thread "main" java.lang.NullPointerException
at _aaaa.main(_aaaa.java:26)
</code></pre>

<p>Here is my program:</p>

<pre><code>import java.util.*;

class pair {
    int first, second;
    pair() {
        first = second = 0;
    }
    public void make_pair(int a, int b)
    {
        first = a;
        second = b;
    }
}
public class aaaa {
    public static void main(String[] idontneedthis)
    {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt(), i, lg = 0;
        int[] A = new int[5010];
        pair[] B = new pair[5010];
        for (N &lt;&lt;= 1, i = 1; i &lt;= N; ++i)
        {
            int var = input.nextInt();
            if (A[var] &gt; 0)
            {
                B[++lg].make_pair(A[var], var);
                A[var] = 0;
            }
            else
            {
                A[var] = i;
            }
        }
        if (lg == 0) System.out.print("-1");
        for (i = 1; i &lt;= lg; ++i)
        {
            System.out.print(B[i].first + " " + B[i].second + "\n");
        }
    }
}
</code></pre>

<p>Please tell me what is wrong or why do I get this error. I mention that if I cut the line 26 ( <code>B[++lg].make_pair(A[var], var);</code> ) it will write -1.</p>

<p>Thank you!</p>
