I have this code i java
I have class

class Author
{
  String name,surname;
  public Author(String name,String surname)
  {
         this.name=name;
         this.surname=surname;
  }
  public String getAName()
{
   return name;
 }
  public String getASurname()
{
    return surname;
}
}

And This code is OK;
I have a button in jFrame class wich adds authors in array

static int nrAuthors=0;
    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {
    Author[] au=new new Author[30];

       String name=jTextField22.getText();
       String surname=jTextField25.getText();
       au[nrAuthors]=new Author(name,surname);
       nrAuthors++;

        // TODO add your handling code here:
    }

And this is OK it means can compile and work properly
but in the other button
I can not have access to the au objects; created objects

private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {
   au[i].getAName();
 
}

au.getAName();
does not work.
can somebody show me any idea pls.

Move the declaration of au outside the action performed method, because now it exists only within that method.

Since you have declared Author[] au=new new Author[30]; in the Jbuttonactionperformed method it cannot be accessed by other methods as it is not a class variable so move this decleration to class level

This question has already been answered. Start a new discussion instead.