So in my class declared as "public class pcb", I have the following constructor: public pcb(int p, int a, int b).
In public static void main(String[] args) I try to call the constructor in a for loop where I add a "pcb" into a different position in an array. Here is the for loop where the last line is where I get the error:
for(int i=0; i<numJob; i++){
pI = scan.nextInt();
arr = scan.nextInt();
bst = scan.nextInt();
notHere[i]=new pcb(pI, arr, bst);
}
What am I doing wrong? Is it syntax or is it the structure of my program. I haven't used Java that much and I think that's my main problem.
You haven't given all of the relevant code, but the error indicates that pcb
is an inner class of fbMain
:
public class fbMain {
//...
public class pcb {
}
//...
}
You can fix this error by making pcb
static:
public static class pcb {
}
Or by moving the class to its own file. Or, if pcb
cannot be static (because it is associated with an instance of fbMain
), you can create a new pcb
by passing an instance of fbMain
:
notHere[i] = instanceOfFbMain.new pcb(pI, arr, bst);
It is likely the first that you want. Please also note that by convention, Java type names start with an upper-case letter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With