java.lang.NullPointerException
I have Implemented this code as shown below but i've seen this error many times: Exception in thread "main" java.lang.NullPointerException at ArrayMethods.addElement(ArrayMethods.java:24) code : // QUEUE IMPLEMENTATION public class Queue{ // INIT QUEUE ARRAY private int[] array; // GET THE CLASS FOR WORK WITH ARRAYS; ArrayMethods am = new ArrayMethods(); // ENQUEUE public int[] enqueue(int elem){ // Something goes here... array = am.addElement(array,elem); return array; } // DEQUEUE public String dequeue(){ // Something goes here... if(array.length == 0) { return "Array is empty"; } else { array=am.removeElement(array,array.length); return "Dequeue!"; } } // PRINT ALL ELEMENTS public int[] elements(){ if(array.length == 0){ return array; } else { return array; } } }