Error: asking to create a new class while accessing innerclass

I am trying to access innerclass Class1 defined in ClassA from ClassB

ClassB.java

public class ClassB implements Initializable {
    public ClassA[] QR;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        for(int i=0; i<1; i++)
        {
            //QR[i] = new ClassA(i);
            QR[i].Class1 class1obj = QR[i].new Class1();

            //prog_QR[i].progressProperty().bind(QR[i].progressProperty());
            prog_QR[i].progressProperty().bind(class1obj.progressProperty());
            //lab_QR[i].textProperty().bind(QR[i].messageProperty());
            lab_QR[i].textProperty().bind(class1obj.messageProperty());
            // My other stuff here
        }
    } 
}

ClassA.java

public class ClassA {    
    public class Class1 extends Task<Integer> {
      // Constructor Created
       Class1() {
        throw new UnsupportedOperationException("Not supported yet."); //To change  body of generated methods, choose Tools | Templates.
    }
       @Override
       protected Integer call() throws Exception {
           // My logic here
       }
    }
}

At line QR[i].Class1 class1obj = QR[i].new Class1();,I am getting an error in Netbeans and it's either askign me to

1) Create class "Class1" in package mypackage

2) Create class "Class1" in mypackage

What am I doing wrong here?

Jon Skeet
people
quotationmark

When you declare a variable, the part to the left of the variable name has to be a type name.

QR[i].Class1

isn't a class name. QR[i] is a value within an array. There isn't a different class for each value in the array. You want:

ClassA.Class1 class1obj = QR[i].new Class1();

Personally I'd try to avoid inner classes unless you really need them anyway. Does your inner class definitely need to be an inner class rather than just a nested class?

In addition, your class declarations are broken. These:

public ClassA {
...
public ClassB {

need to be:

public class ClassA {
...
public class ClassB {

As a complete example, this code compiles fine:

public class ClassA {
    public class Class1 {}
}

public class ClassB {    
    public ClassA[] QR = new ClassA[1];

    public void foo() {
        QR[0] = new ClassA();
        ClassA.Class1 class1obj = QR[0].new Class1();
    }
}

people

See more on this question at Stackoverflow