No instance of type fbMain available. Must qualify the selection using an instance of type fbMain

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 "pcb" to another position in the array. Here is a for loop where the last line contains an 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 this the syntax or is this the structure of my program. I have not used Java very much, and I think that my main problem.

+8
java
source share
2 answers

You did not specify all 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 moving the class to its own file. Or, if pcb cannot be static (since it is associated with an fbMain instance), you can create a new pcb by passing the fbMain instance:

 notHere[i] = instanceOfFbMain.new pcb(pI, arr, bst); 

This is most likely the first thing you want. Also note that by convention, Java type names begin with an uppercase letter.

+15
source share

Add static to your class declaration, e.g.

 public static class pcb... 
+3
source share

All Articles