For my university assignment i'm trying to pass an int as a parameter to another class. However I keep receiving a null error for some reason. I even printed out the integer to see if it was null but it wasn't. Now I don't know what the problem could be. I've been trying different stuff for a couple hours now and I thought I should post my issue here.
I created a field in this class called currentBuild so that I can call methods in the Build class.
private Build currentBuild;
This is my method that gets the integer from the user and sends it to another class called Build.
private void addFromCat(){
int partNo;
System.out.println("Enter catalogue number of the part: ");
partNo = In.nextInt();
System.out.println(partNo);
currentBuild.getNum(partNo);
}
This is the method in the Build class that receives the integer. It's called getNum.
public class Build
{
private List <Part> parts = new ArrayList <Part>();
/**
* Constructor for objects of class Build
*/
public Build()
{
}
public void getNum(int partNo){
int numberPart = partNo;
System.out.println("part number is: " + numberPart);
}
}