package assignment; import java.util.*; import java.util.Stack; public class Assignment { public static void main(String[] args) { // TODO code application logic here boolean exit = false; boolean flag = false; MyArrayList<GenericStack[][]>region = new MyArrayList<>(); Container container = new Container(); GenericStack<Container>[][]storage=new GenericStack[10][10]; while(exit == false){ System.out.println("Please select the function that you want to preform"); System.out.println("1) Load Container into region"); System.out.println("2) Unload the container from the region"); Scanner input = new Scanner(System.in); int selection = input.nextInt(); //switch case to select option switch(selection){ case 1 : LoadObject( storage, container); break; default: System.out.println("Please key in the correct input :"); }//end of the switch case //option for exit while(flag==true) System.out.println("Do you want to exit ? (Y/N))"); Scanner inputExit = new Scanner(System.in); if(inputExit.nextInt()=='Y' || inputExit.nextInt()== 'y') exit = true; else if( inputExit.nextInt()=='N' || inputExit.nextInt()=='n') exit = false; else { //If the user key in a non-valid input System.out.print("Please key in the correct input."); flag =true; } } }//end of thw while loop public static void LoadObject(GenericStack[][]storage, Container container){ System.out.println("How many container"); Scanner input = new Scanner(System.in); int counter = input.nextInt(); int i, j; for(i = 0; i <10 ; i++){ for(j = 0 ; j< 10 ; j++){ if(counter>0){ if(!storage[i][j].isEmpty()){ //<-------- for(i = storage[i][j].getSize() ; i < 10 ; i++ ){ System.out.println("Please key in the container id :\n"); int objectId = input.nextInt(); container.SetObjectId(objectId); System.out.println("Please key in the container description :\n"); String objectDesc = input.nextLine(); container.SetObjectDesc(objectDesc); storage[i][j].push(container); counter--; }//end of the insertion } }//end of the number of container else i = 10; j =10;//end the check empty if is finish container }//end of the for loop }//end of the for loop } }
Here is part of my coding @@
i have no idea why there is a "NullPointerException" error when i run it. I have no idea what it is please help me.